gpt4 book ai didi

xslt - concat、引号和撇号组合问题

转载 作者:行者123 更新时间:2023-12-03 18:27:02 24 4
gpt4 key购买 nike

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

"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 实体似乎都不起作用。

任何帮助都非常感谢。

谢谢!

最佳答案

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

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

  • concat 字符串中的撇号的问题在于,加载 XSLT 的 XML 解析器将在 XSLT 引擎评估 concat 之前对其进行扩展;所以你不能对撇号字符使用实体引用,除非它用双引号包裹(或双引号的实体引用,如 Dimitre Novatchev 的回答所示)。
  • 使用实体引用 "对于双引号 " .
  • 为撇号字符创建一个变量,并将该变量作为 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 的答案将是最好的。

    如果您关心阅读、理解和维护的难易程度,那么 Michael Kay 建议将 XSLT 变量用于引号和撇号可能是最好的。

    关于xslt - concat、引号和撇号组合问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8783086/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com