XSL transformation attributes to elements

前提是你 提交于 2021-02-05 11:14:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!