Xslt 要匹配的Xpath谓词<;![CDATA[sometext]]>;
我的xml元素内容具有特殊字符,如,[,]。我想在内容Xslt 要匹配的Xpath谓词<;![CDATA[sometext]]>;,xslt,xpath,special-characters,Xslt,Xpath,Special Characters,我的xml元素内容具有特殊字符,如,[,]。我想在内容中找到元素maching,并将其替换为一些新值,如 ` 我正试图使用下面的xsl模板来实现这一点。但它不起作用 <xsl:template match="property[string='<![CDATA[someText]]>']"> <xsl:element name="string"> <xsl:text dis
中找到元素maching,并将其替换为一些新值,如
`
我正试图使用下面的xsl模板来实现这一点。但它不起作用
<xsl:template match="property[string='<![CDATA[someText]]>']">
<xsl:element name="string">
<xsl:text disable-output-escaping="yes"><![CDATA[newValue]]></xsl:text>
</xsl:element>
![CDATA[newValue]]
请提供帮助。XML信息集中未显示CDATA部分,因此其内容仅为常规文本—一个完整的文本节点或文本节点的一部分 在您的情况下,CDATA部分是完整的文本节点,因此您可以拥有:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
当此转换应用于以下XML文档时:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
你好,世界]>
生成所需的正确结果:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
你好]>
XML信息集中没有显示CDATA节,因此它的内容只是普通文本——一个完整的文本节点或文本节点的一部分
在您的情况下,CDATA部分是完整的文本节点,因此您可以拥有:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
当此转换应用于以下XML文档时:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
你好,世界]>
生成所需的正确结果:
<xsl:template match="property[string='someEscapedText']">
<string>newEscapedValue</string>
</xsl:template>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output cdata-section-elements="string"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match=
"property[string='<p>Hello, World</p>']">
<string><p>Hello, You</p></string>
</xsl:template>
</xsl:stylesheet>
<property>
<string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
你好]>