问题
I would like to convert xml attributes of input xml to elements of output xml. Example
<Price price1="2" price2="3" total="5" other="x" tax="2"/> to
<Price>
<price1>2</price1>
<price2>3</price2>
<total>5</total>
<other>x</other>
<tax>2</tax>
</Price>
I tried like
<xsl:element name="Price">
<xsl:for-each select="*:Price/@*">
<xsl:element name="*>
<xsl:value-of select="@*"/>
</xsl:for-each>
</xsl:element></xsl:element>
Not able to get the required output.Please suggest.
回答1:
Try it this way:
<xsl:template match="Price">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
来源:https://stackoverflow.com/questions/42273028/xsl-transformation-attributes-to-elements