我们如何检查节点重新调整内的值,即
飓风烧烤达令港
实际上,我无法使用以下代码选择撇号
存在(// ns1:name [text()='Hurricane's Grill Darling Harbour'])。
收到错误消息:
RuntimeException:net.sf.saxon.trans.XPathException:{... name [text()='Hurricane's Gr ...}:第2行中char 33处的XPath语法错误:预期为“]”,发现名称为“ s”
最佳答案
我无法使用以下代码选择撇号
存在(// ns1:name [text()='Hurricane's Grill Darling Harbour'])。
正在获取错误消息:RuntimeException:net.sf.saxon.trans.XPathException:XPath语法错误,位于{... name [text()='Hurricane's Gr ...}}中第2行的char 33处:
预期为“]”,找到名称为“ s”
在XPath 2.0中,只需将字符加倍即可转义撇号或双引号。在此处查看规则[75]和[76]:http://www.w3.org/TR/xpath20/#terminal-symbols
用:
exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])
基于XSLT 2.0的验证:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:sequence
select="exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])"/>
</xsl:template>
</xsl:stylesheet>
在以下XML文档上应用此转换时:
<ns1:name xmlns:ns1="ns1">Hurricane's Grill Darling Harbour</ns1:name>
所需的正确结果产生了:
true
如果您只能在XML文档中使用XPath 1.0表达式,并且该字符串包含两种引号,请使用:
boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])
这是完整的基于XSLT 1.0的验证:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select=
"boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])"/>
</xsl:template>
</xsl:stylesheet>
在以下XML文档上应用此转换时:
<ns1:name xmlns:ns1="ns1">Hurricane "Mathew" strength's value</ns1:name>
所需的正确结果产生了:
true
关于xpath - 在SOAP UI中声明的Xpath表达式:如何处理节点值(例如Abc的作品)的撇号等特殊符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39901210/