简体   繁体   中英

How to construct xml from another xml using xslt3.0 where xml attribute values should be the new element names

I am looking for an xslt transformation[version 3.0] from one xml to another xml where attribute values in first xml should be the element tags in transformed xml, for example

First XML:

<number key="id">2</number>
<string key="name">An ice sculpture</string>
<number key="price">12.50</number>

Transformed XML should be like

<id>2</id>
<name>An ice sculpture</name>
<price>12.50</price>

Is this possible?

You just need a template rule like

<xsl:template match="*[@key]">
  <xsl:element name="{@key}">{.}</xsl:element>
</xsl:template>

Of course the details depend on what else might occur in the file, whether you want to do error handling, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM