Xml Xslt更改元素名称
我想用xslt更改xml元素 XML: 我尝试使用以下xslt对其进行更改:Xml Xslt更改元素名称,xml,xslt,Xml,Xslt,我想用xslt更改xml元素 XML: 我尝试使用以下xslt对其进行更改: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="MT[@N='ur
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="MT[@N='url_id']">
<xsl:attribute name="url-id">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
我想把url_id改成url-id
结果应该如下所示:
<PARAM name="ulang" value="de" original_value="de"/>
<PARAM name="ulang" value="de" original_value="de"/>
<PARAM name="wc" value="200" original_value="200"/>
<PARAM name="wc_mc" value="1" original_value="1"/>
<RES SN="1" EN="727">
<M>727</M>
<XT/>
<R N="1" L="1" MIME="text/plain">
<U>url</U>
<UE>url</UE>
<UD>url</UD>
<RK>10</RK>
<MT N="Content_Length" V="42"/>
<MT N="url-id" V="005056A51FAC1EE0B9A3EF696BB229CB"/>
谢谢 您的模板正在匹配MT元素,并尝试创建一个属性来代替该元素 您需要将模板改为与属性匹配
<xsl:template match="MT/@N[. = 'url_id']">
<xsl:attribute name="N">
<xsl:value-of select="'url-id'"/>
</xsl:attribute>
</xsl:template>
甚至这个
<xsl:template match="MT/@N[. = 'url_id']">
<xsl:attribute name="N">url-id</xsl:attribute>
</xsl:template>
您的问题提到更改元素名称,但看起来您实际上想要更改属性?是否要更改属性的值或属性的名称?如果显示希望输出的XML,可能会有所帮助。谢谢我添加了我期望的结果。
<xsl:template match="MT/@N[. = 'url_id']">
<xsl:attribute name="N">url-id</xsl:attribute>
</xsl:template>