Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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中无用的match=text()_Xml_Xslt - Fatal编程技术网

Xml XSLT中无用的match=text()

Xml XSLT中无用的match=text(),xml,xslt,Xml,Xslt,当练习要求我将文本从输入复制到输出时,我通常会输入以下代码: <xsl:template match="text()"> <xsl:value-of select="."/> </xsl:template> 但我注意到几乎总是没用的。在任何情况下,我必须使用此代码,否则它总是无用的 例如,在这种情况下,无论有无这三行代码,输出都是相同的: 输入: 测试0 testo 1 testo 2 Testo3 Testo4 testo 5

当练习要求我将文本从输入复制到输出时,我通常会输入以下代码:

<xsl:template match="text()">
        <xsl:value-of select="."/>
</xsl:template>

但我注意到几乎总是没用的。在任何情况下,我必须使用此代码,否则它总是无用的

例如,在这种情况下,无论有无这三行代码,输出都是相同的: 输入:


测试0
testo 1

testo 2

Testo3 Testo4 testo 5 testo 6

期望输出:

<z>
<nuovo livelloInput="figlio radice">testo 0
<rad livelloInput="nipote radice">testo 1</rad>
</nuovo>
<nuovo livelloInput="figlio radice">
<p livelloInput="nipote radice">testo 2</p>
</nuovo>
<nuovo livelloInput="figlio radice">
<p livelloInput="nipote radice"/>
<y livelloInput="nipote radice">testo 3 testo 4</y>
<p livelloInput="nipote radice">testo 5 testo 6</p>
<p livelloInput="nipote radice"/>
</nuovo>
<nuovo livelloInput="figlio radice"/>
</z>

测试0
testo 1
testo 2

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"/>
    <xsl:template match="/*">
        <xsl:element name="{name()}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="/*/*">
        <nuovo>
            <xsl:attribute name="livelloinput">figlioradice</xsl:attribute>
            <xsl:apply-templates></xsl:apply-templates>
        </nuovo>
    </xsl:template>
    <xsl:template match="/*/*/*">
        <xsl:element name="{name()}">
            <xsl:attribute name="livelloInput">nipoteradice</xsl:attribute>
            <xsl:apply-templates></xsl:apply-templates>
        </xsl:element>
    </xsl:template>
    <xsl:template match="text()">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>

菲格利奥拉迪克
尼波特拉迪

这是文本节点的默认行为,因为。所以你不需要那个模板

<?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"/>
    <xsl:template match="/*">
        <xsl:element name="{name()}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="/*/*">
        <nuovo>
            <xsl:attribute name="livelloinput">figlioradice</xsl:attribute>
            <xsl:apply-templates></xsl:apply-templates>
        </nuovo>
    </xsl:template>
    <xsl:template match="/*/*/*">
        <xsl:element name="{name()}">
            <xsl:attribute name="livelloInput">nipoteradice</xsl:attribute>
            <xsl:apply-templates></xsl:apply-templates>
        </xsl:element>
    </xsl:template>
    <xsl:template match="text()">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>