Xml 使用XSLT转义未使用的值
我有一个Xml 使用XSLT转义未使用的值,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我有一个XSLT转换: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" version="1.0"
XSLT
转换:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"
indent="yes"
version="1.0"
encoding="UTF-16"
standalone="yes"
cdata-section-elements="title date referencenumber url company city state country postalcode description salary education jobtype category experience"/>
<xsl:param name="currentDate"/>
<xsl:template match="/response/result">
<source>
<xsl:for-each select="//doc">
<job>
<title>
<xsl:value-of select="str[@name='title']"/>
</title>
<date>
<xsl:value-of select="date[@name='ds_field_ad_publish']"/>
</date>
<referencenumber>
<xsl:value-of select="int[@name='nid']"/>
</referencenumber>
</job>
</xsl:for-each>
</source>
</xsl:template>
</xsl:stylesheet>
我正在匹配/response/result
,然后循环遍历所有
元素。一切正常,但在我的文档顶部,我看到了
元素中的值。像这样:
0
4
xml
type:ad_vacancy is_organisation_nid:190908
1000000
我需要以某种方式逃离整个街区,我的转变将无法与之匹配。我尝试过不同的表达方式,如:
,
。我还试着把这一点加入到我的转变中:
<xsl:template match="/*">
<xsl:apply-templates/>
</xsl:template>
但这并没有起到同样的作用。
中的值仍然保留。有办法摆脱它们吗?只需将此添加到模板中:
它匹配文本节点和属性,并且由于模板为空,因此对它们不做任何处理。它实际上是一个“内置模板”-->
您编辑的XSLT如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"
indent="yes"
version="1.0"
encoding="UTF-16"
standalone="yes"
cdata-section-elements="title date referencenumber url company city state country postalcode description salary education jobtype category experience"/>
<xsl:param name="currentDate"/>
<xsl:template match="text() | @*"/>
<xsl:template match="/response/result">
<source>
<xsl:for-each select="//doc">
<job>
<title>
<xsl:value-of select="str[@name='title']"/>
</title>
<date>
<xsl:value-of select="date[@name='ds_field_ad_publish']"/>
</date>
<referencenumber>
<xsl:value-of select="int[@name='nid']"/>
</referencenumber>
</job>
</xsl:for-each>
</source>
</xsl:template>
</xsl:stylesheet>
致以最良好的祝愿,
Peter只需将此添加到模板中:
它匹配文本节点和属性,并且由于模板为空,因此对它们不做任何处理。它实际上是一个“内置模板”-->
您编辑的XSLT如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"
indent="yes"
version="1.0"
encoding="UTF-16"
standalone="yes"
cdata-section-elements="title date referencenumber url company city state country postalcode description salary education jobtype category experience"/>
<xsl:param name="currentDate"/>
<xsl:template match="text() | @*"/>
<xsl:template match="/response/result">
<source>
<xsl:for-each select="//doc">
<job>
<title>
<xsl:value-of select="str[@name='title']"/>
</title>
<date>
<xsl:value-of select="date[@name='ds_field_ad_publish']"/>
</date>
<referencenumber>
<xsl:value-of select="int[@name='nid']"/>
</referencenumber>
</job>
</xsl:for-each>
</source>
</xsl:template>
</xsl:stylesheet>
致以最良好的祝愿,
Peter有一些内置模板,您需要使用它们进行覆盖
<xsl:template match="text()"/>
或防止被用于
<xsl:template match="/">
<xsl:apply-templates select="response/result"/>
</xsl:template>
有一些内置模板,您需要使用它们进行覆盖
<xsl:template match="text()"/>
或防止被用于
<xsl:template match="/">
<xsl:apply-templates select="response/result"/>
</xsl:template>