Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何编写xpath来选择其文本包含特殊字符(如撇号)的节点?_Xml_Xslt_Xpath_Apostrophe - Fatal编程技术网

Xml 如何编写xpath来选择其文本包含特殊字符(如撇号)的节点?

Xml 如何编写xpath来选择其文本包含特殊字符(如撇号)的节点?,xml,xslt,xpath,apostrophe,Xml,Xslt,Xpath,Apostrophe,如何编写xpath来选择其文本包含特殊字符的节点,例如“这在xpath中是无效的?” <Nodes><Node><Text>General Marketing'</Text><Nodes><Node><Text>Brochures</Text></Node><Node><Text>Value-Added</Text><Nodes><No

如何编写xpath来选择其文本包含特殊字符的节点,例如“这在xpath中是无效的?”

<Nodes><Node><Text>General Marketing'</Text><Nodes><Node><Text>Brochures</Text></Node><Node><Text>Value-Added</Text><Nodes><Node><Text>About Henderson</Text></Node><Node><Text>Own the World</Text></Node></Nodes></Node></Nodes></Node></Nodes>
上述xpath失败,因为xpath包含以下文本:

/Nodes/Node[Text = 'General Marketing''] 
正如你所看到的,有两个使徒

从我的测试到目前为止,它只有'的问题。不确定是否有任何其他特殊字符可能有问题

所以我想我需要修改我的xpath,使之成为其他的东西

我尝试了以下方法,但没有成功:

var xPath = String.Format("/Nodes/Node[Text = \"{0}\"]", branchName);
希望问题清楚

谢谢,请使用:

//Text[.="General Marketing'"]
<Nodes>
    <Node>
        <Text>General Marketing'</Text>
        <Nodes>
            <Node>
                <Text>Brochures</Text>
            </Node>
            <Node>
                <Text>Value-Added</Text>
                <Nodes>
                    <Node>
                        <Text>About Henderson</Text>
                    </Node>
                    <Node>
                        <Text>Own the World</Text>
                    </Node>
                </Nodes>
            </Node>
        </Nodes>
    </Node>
</Nodes>
<Text>General Marketing'</Text>
如果在XSLT中使用此XPath表达式,则整个XPath表达式myst将被撇号包围,并且由引号包围的字符串的最后一个字符(撇号)必须使用内置实体
&apos

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
  <xsl:copy-of select='//Text[.="General Marketing&apos;"]'/>
 </xsl:template>
</xsl:stylesheet>
其中变量
$vQ
定义为:

<xsl:variable name="vQ">'</xsl:variable>
'
//Text[. = concat('General Marketing', $vQ)]
<xsl:variable name="vQ">'</xsl:variable>