concat,引号和撇号组合问题 [英] concat, quotation mark and apostrophe combination problems

查看:100
本文介绍了concat,引号和撇号组合问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了不同的方法,也环顾了四周,但无法运行。
我需要合并以下内容:

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',
    //XML_NODE,
    '\"; \"using an apostrophe',
    ''',
    'in text\"'
)"

单行版本:

"concat( 'this is; \"a sample', //XML_NODE, '\"; \"using an apostrophe', ''', 'in text\"' )"

输出应为:

this is "a sample XML_NODE_VALUE"; "using an apostrophe ' in text"

问题是文本中的’。 concat使用它结束字符串并期望跟随;或联结期结束。转义或HTML实体似乎都无法正常工作。

The problem is the ' in the text. concat use it to end a string and expect an following ; or the end of concat. Escaping or HTML entities all seems to not work.

我们非常感谢您的帮助。

Any help is really appreciated.

谢谢!

推荐答案

在XML / XSLT中,您不会使用反斜杠转义字符。

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


  • 在XML中,您可以使用实体引用。

  • 在XSLT中,您可以使用实体引用和变量。

内部撇号的问题您的concat字符串的含义是,加载XSLT的XML解析器将在concat得到XSLT引擎评估之前对其进行扩展;因此,除非将引号字符括在双引号中,否则您不能使用实体引用(如Dimitre Novatchev的答案所示,则将实体引用用于双引号)。

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).


  • 将实体引用& 用作双引号

  • 为撇号字符创建一个变量,并将该变量作为concat()的组成部分之一引用

  • 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()

在XSLT中应用:

<xsl:variable name="apostrophe">'</xsl:variable>

<xsl:value-of select="concat( 
            'this is; &quot;a sample',
            //XML_NODE,
            '&quot;; &quot;using an apostrophe ',
            $apostrophe,
            ' in text&quot;'
            )" />

如果您需要避免使用XSLT变量的100%XPath解决方案,那么Dimitre的答案将是最好。

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

如果您担心阅读,理解和维护的难易程度,那么Michael Kay建议使用XSLT变量作为引号和撇号。最好。

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.

这篇关于concat,引号和撇号组合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆