Hi,
I am new to XSLT, Please helo me in transforming the XML to XML transform
I have XML like this

<products>
<product>
<display value="32" />
<count value="0"/>
</product>
</products>

Through XSLT I need to convert it like this

<products>
<product display="32" count="0"/>
</products>

Please help me out. This is very urgent requirement.

Regards,
Hanuman

This is really, really simple. You should be able to do this very easily if you're in a class or something. If not you need to visit http://www.w3schools.com/xsl/ and start doing the tutorial. This should take you maybe a couple hours tops if you have any development experience.

Once you actually ATTEMPT a solution, I'll be willing to help you fix it. Post your attempt (please use codeboxes, for your xml documents) and I'll happy to help.

Hi andrwes,
Thanks a lot for replying.
Sure that iwill learn. But their is a urgent requirement to fit this code in to a project. Can u please help me in this.

Regards,
Hanuman

<xsl:template match="product">
<product>
<xsl:attribute name="display" select="child::display[@value]"/>
<xsl:attribute name="count" select="child::count[@value]"/>
</product>
</xsl:templste>

This works for XSLT1

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

   <xsl:template match="product">
   <product>
       <xsl:attribute name="display">
           <xsl:value-of select="display/@value"/>
       </xsl:attribute>
       <xsl:attribute name="count">
          <xsl:value-of select="count/@value"/>
       </xsl:attribute>
   </product>
   </xsl:template>

</xsl:stylesheet>

<xsl:template match="product">
<product>
<xsl:attribute name="display" select="child::display[@value]"/>
<xsl:attribute name="count" select="child::count[@value]"/>
</product>
</xsl:templste>

Note the use of a select attribute with the <xsl:attribute> instruction. This attribute is only available in XSLT2

This article has been dead for over six months. Start a new discussion instead.