Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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 使用XSLT转义未使用的值_Xml_Xslt_Xslt 2.0 - Fatal编程技术网

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>