xsl-list
[Top] [All Lists]

Re: Adding the child nodes as attributes to the parent node.

2005-07-15 02:07:46
Please try this XSL..

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 
<xsl:output method="xml" indent="yes" /> 

<xsl:template match="Element">
  <xsl:element name="{concat(@type,'-Element')}">
    <xsl:for-each select="attribute">
      <xsl:attribute name="{(_at_)name}">
        <xsl:value-of select="@value" />
      </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates select="Element" />
  </xsl:element>
</xsl:template>
 
</xsl:stylesheet>

Regards,
Mukul


--- Lakshmi narayana <lchintala(_at_)osi-tech(_dot_)com> wrote:



Hi,
I have the following xml file. I want to write the
xslt to this file.
In the resultant xml file, all the immediate
attribute childs of a node are
processed and add the attributes of that attribute
child
as attributes to the parent node. Based on the type,
the parent element node
should be changed.
Only attribute tag attributes should be added to its
parent.
Can any one give the xslt code for this.

Input file
<Element type="A">
      <attribute name="seq" value="1"/>
      <attribute name="rep" value="2"/>
      <attribute name="Period" value="3"/>
      <Element type="B">
              <attribute name="seq" value="4"/>
              <attribute name="rep" value="5"/>
              <Element type="C">
                      <attribute name="seq" value="6"/>
                      <attribute name="rep" value="7"/>
                      <attribute name="period" value="8"/>
                      <attribute name="max" value="9"/>
              </Element>
      </Element>
</Element>

output file:
<A-Element seq="1" rep="2" period="3">
      <B-Element seq="4" rep="5">
              <C-Element  seq="6" rep="7" period="8" max="9">
              </C-Element>
      </B-Element>
</A-Element>
Thanks,
Laxmi Narayana




--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>