模板未应用 XSLT

template not getting applied with XSLT

我正在使用 xslt 将 xml 转换为 xml。

<root>
 <elem>
  <confs>
   <conf1>1</conf1>
   <conf2>2</conf2>
  </confs>
 </elem>
</root>

我的 XSL

<xsl:template match="elem">
 <xsl:copy>
  <xsl:attribute name="className">confs</xsl:attribute>
  <xsl:apply-templates/>
 </xsl:copy>
</xsl:template>

<xsl:template match="confs">
 <confs>
  <xsl:for-each select="*">
   <conf>
    <value>
     <xsl:value-of select="node()"></xsl:value-of>
    </value>
   </conf>
 </confs>
</xsl:template>

期望的输出:

<root>
 <elem className="confs>
  <confs>
   <conf>
    <value>1</value>
   </conf>
   <conf>
    <value>1</value>
   </conf>
  </confs>
 </elem>
 </root>

当运行 每个模板都很好。但是我运行两个confs模板一点都不受影响

有什么帮助吗?

我认为实现输出的最直接方法是:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="elem">
    <elem className="confs">
        <xsl:apply-templates/>
    </elem>
</xsl:template>

<xsl:template match="confs/*">
    <conf>
        <value>
            <xsl:value-of select="."/>
        </value>
   </conf>
</xsl:template>

</xsl:stylesheet>