concat, quotation mark and apostrophe combination problems

前端 未结 3 1164
后悔当初
后悔当初 2021-01-19 10:11

I tried different ways and also looked around but can\'t get this running. I need to concat the following:

\"concat( 
    \'this is; \\\"a sample\',
    //XM         


        
3条回答
  •  一个人的身影
    2021-01-19 10:36

    In XML/XSLT you do not escape characters with a backslash.

    • In XML you can use entity references.
    • In XSLT you can use entity references and variables.

    The problem with the apostrophe inside of your concat strings is that the XML parser loading the XSLT will expand it before the concat gets evaluated by the XSLT engine; so you can't use an entity reference for the apostrophe character unless it is wrapped in double quotes (or entity references for double quotes, as Dimitre Novatchev's answer demonstrates).

    • Use the entity reference " for the double quote ".
    • Create a variable for the apostrophe character and reference the variable as one of the components of the concat()

    Applied in the context of an XSLT:

    '
    
    
    

    If you need a 100% XPath solution that avoids the use of XSLT variables, then Dimitre's answer would be best.

    If you are concerned with how easy it is to read, understand, and maintain, then Michael Kay's suggestion to use XSLT variables for the quote and apostrophe might be best.

提交回复
热议问题