Hi, I have a custom XML that I need to transform to another XML format, using XSL.
Input:
<Feed>
<repository>
<item-descriptor name="product">
<property name="id">123</property>
<property name="display">asdf</property>
<property name="attr1">attr1</property>
<property name="attr2">attr2</property>
</item-descriptor>
</repository>
</Feed>
Output:
<Feed>
<Products>
<product>
<id>123</id>
<display>asdf</display>
<attr1>attr1</attr>
<attr2>attr2</attr2>
</product>
</Products>
</Feed>
Following XSL is used to get the desired output.
XSL:
<xsl:template match="/">
<xsl:apply-templates select="Feed"/>
</xsl:template>
<xsl:template match="Feed">
<Feed>
<Products>
<xsl:apply-templates select="repository/item-descriptor[@name='product']"/>
</Products>
</Feed>
</xsl:template>
<xsl:template match="repository/item-descriptor[@name='product']">
<product>
<xsl:apply-templates select="property"/>
</product>
</xsl:template>
<xsl:template match="property">
<xsl:if test=@name='id'>
<id><xsl:value-of select='.'></id>
</xsl:if> <xsl:if test=@name='display'>
<display><xls:value-of select='.'></display>
<xsl:if test=@name='attr1'>
<attr1><xsl:value-of select='.'></attr1>
</xsl:if>
<xsl:if test=@name='attr2'>
<attr2><xls:value-of select='.'></attr2>
</xsl:template>
Now I need to generate the following output, please help me out in modifying the above XSL to get the output below:
<Feed>
<Products>
<product>
<id>123</id>
<display>asdf</display>
<attributes>
<aatr1>attr1</attr1>
<attr2>attr2</attr2>
</attributes>
</product>
</Products>
</Feed>