【问题标题】:XPath concat function: \n appears as textXPath concat 函数:\n 显示为文本
【发布时间】:2022-01-05 12:07:42
【问题描述】:

我正在使用 concat 函数编写 Xpath 脚本以使用 XPath 1.0 以行显示结果

XML 示例

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

XPath

concat("To : ", /note/to , ' \n  ', "From : ", /note/from, ' \n  ', "Heading : ", /note/heading, ' \n  ', "Body : ", /note/body)

结果

To : Tove \n  From : Jani \n  Heading : Reminder \n  Body : Don't forget me this weekend!

但是,当我使用带有两个元素和“\n”之间的 concat 时,它可以正常工作。

xPath:

concat("To : ", /note/to , ' \n  ', "From : ", /note/from)

结果:

To : Tove 
From : Jani

【问题讨论】:

  • 使用 而不是 \n
  • 很遗憾,它并没有解决问题
  • 向我们展示您的 XSLT 代码。仅仅添加一个标签是不够的。
  • 我用的是Infor M3 ERP系统所以我们得到路径,然后字符串结果从“字符串到二维码”转换
  • 我不知道 Infor M3 ERP 系统是什么。请提供minimal reproducible example

标签: string xpath concatenation xslt-1.0 xpath-1.0


【解决方案1】:

XPath 不将反斜杠识别为转义字符。 "\n" 只代表“反斜杠,'n'”这两个字符,不代表换行。

如果您的 XPath 表达式嵌入在 Java 或 C# 等宿主语言中,那么宿主语言将在 XPath 引擎看到之前将 \n 转换为换行符。但是您没有提及表达式出现的宿主语言。

如果您的 XPath 表达式出现在 XSLT 或 XQuery 中,那么您应该写一个换行符为&amp;#xa;&amp;#x10;。如果是其他环境,则可以使用文字换行符。

所以答案是,这完全取决于您编写这些表达式的宿主环境。

【讨论】:

  • 字符串中的字符显示为txt。问题还没有解决。希望有另一种方式。
  • 好吧,您可以从回答以下问题开始:您是如何运行此 XPath 表达式的?
猜你喜欢
  • 1970-01-01
  • 2015-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2023-03-06
相关资源
最近更新 更多