Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Xslt 要匹配的Xpath谓词<;![CDATA[sometext]]>;_Xslt_Xpath_Special Characters - Fatal编程技术网

Xslt 要匹配的Xpath谓词<;![CDATA[sometext]]>;

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

我的xml元素内容具有特殊字符,如,[,]。我想在内容
中找到元素maching,并将其替换为一些新值,如


`
我正试图使用下面的xsl模板来实现这一点。但它不起作用

<xsl:template match="property[string='<![CDATA[someText]]>']">    
   <xsl:element name="string">                 
                <xsl:text disable-output-escaping="yes">&lt;![CDATA[newValue]]&gt;</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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/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='&lt;p>Hello, World&lt;/p>']">
   <string>&lt;p>Hello, You&lt;/p></string>
 </xsl:template>
</xsl:stylesheet>
<property>
 <string><![CDATA[<p>Hello, World</p>]]></string>
</property>
<string><![CDATA[<p>Hello, You</p>]]></string>
你好

]>