Xml XSLT-模板未应用于某些节点

Xml XSLT-模板未应用于某些节点,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我有一个这样的xml <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company&g

我有一个这样的xml

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
    <cd>
        <title>Unchain my heart</title>
        <artist>Joe Cocker</artist>
        <country>USA</country>
        <company>EMI</company>
        <price>8.20</price>
        <year>1987</year>
    </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
1988
释放我心
乔·库克
美国
电磁干扰
8.20
1987
我需要做的是从原始xml中删除
节点,将
节点更改为
,并在最后的
节点末尾添加新节点(

我编写了以下XSLT代码

<xsl:variable name="time" as="xs:dateTime" select="current-dateTime()"/>
<xsl:variable name="version" as="xs:double" select="1.0"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="catalog/cd/artist">
        <name><xsl:apply-templates/></name>
    </xsl:template>

    <xsl:template match="catalog/cd/year"/>

    <xsl:template match="catalog/cd[last()]">
        <xsl:copy-of select="."/>
        <time><xsl:value-of select="$time"/></time>
        <version><xsl:value-of select="$version"/></version>
    </xsl:template>

输出如下:

<?xml version="1.0" encoding="UTF-8"?><catalog>
    <cd>
        <title>Empire Burlesque</title>
        <name>Bob Dylan</name>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>

    </cd>
    <cd>
        <title>Hide your heart</title>
        <name>Bonnie Tyler</name>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>

    </cd>
    <cd>
        <title>Unchain my heart</title>
        <artist>Joe Cocker</artist>
        <country>USA</country>
        <company>EMI</company>
        <price>8.20</price>
        <year>1987</year>
    </cd>
    <time>2015-06-29T13:41:49.885+05:30</time>
    <version>1</version>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
释放我心
乔·库克
美国
电磁干扰
8.20
1987
2015-06-29T13:41:49.885+05:30
1.
正如您所看到的,代码工作正常,但只有final节点似乎未应用模板(在final节点中
节点未更改
节点出现)


我怎样才能解决这个问题

在上一个模板中,替换:

<xsl:copy-of select="."/>

与:


更改

<xsl:template match="catalog/cd[last()]">
    <xsl:copy-of select="."/>
    <time><xsl:value-of select="$time"/></time>
    <version><xsl:value-of select="$version"/></version>
</xsl:template>


<xsl:template match="catalog/cd[last()]">
    <xsl:copy-of select="."/>
    <time><xsl:value-of select="$time"/></time>
    <version><xsl:value-of select="$version"/></version>
</xsl:template>
<xsl:template match="catalog/cd[last()]">
    <xsl:copy>
      <xsl:apply-templates>
      <time><xsl:value-of select="$time"/></time>
      <version><xsl:value-of select="$version"/></version>
    </xsl:copy>
</xsl:template>