Converting and rename attribute values to elements
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Mon Sep 17, 2007 1:42 am
Converting and rename attribute values to elements
How would I convert and rename the attribute "key" value to a corresponding element using xslt?
<record>
<properties>
<property key="Category">Male</property>
<property key="Product">Shoe</property>
<property key="Color">Green</property>
<property key="Region">Europe</property>
<property key="Date">11/11/2008</property>
<property key="ProductType">Running</property>
</properties>
</record>
to
<record>
<properties>
<cat>Male</cat>
<prd>Shoe</prd>
<col>Green</col>
<rgn>Europe</rgn>
<dat>11/11/2008</dat>
<pdt>Running</pdt>
</properties>
</record>
thanks
<record>
<properties>
<property key="Category">Male</property>
<property key="Product">Shoe</property>
<property key="Color">Green</property>
<property key="Region">Europe</property>
<property key="Date">11/11/2008</property>
<property key="ProductType">Running</property>
</properties>
</record>
to
<record>
<properties>
<cat>Male</cat>
<prd>Shoe</prd>
<col>Green</col>
<rgn>Europe</rgn>
<dat>11/11/2008</dat>
<pdt>Running</pdt>
</properties>
</record>
thanks
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
There are many possible solutions, one way to do it is like below
Best Regards,
George
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<record>
<properties>
<xsl:apply-templates/>
</properties>
</record>
</xsl:template>
<xsl:template match="property[@key='Category']">
<cat><xsl:value-of select="."/></cat>
</xsl:template>
<xsl:template match="property[@key='Product']">
<prd><xsl:value-of select="."/></prd>
</xsl:template>
<xsl:template match="property[@key='Color']">
<col><xsl:value-of select="."/></col>
</xsl:template>
<xsl:template match="property[@key='Region']">
<rgn><xsl:value-of select="."/></rgn>
</xsl:template>
<xsl:template match="property[@key='Date']">
<dat><xsl:value-of select="."/></dat>
</xsl:template>
<xsl:template match="property[@key='ProductType']">
<pdt><xsl:value-of select="."/></pdt>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service