This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Converting attributes to elements and preserving the hierarchy
- From: "Samuel Abraham" <samuel dot abraham at db dot com>
- To: XSL-List at lists dot mulberrytech dot com
- Date: Wed, 19 Dec 2001 15:56:28 +0800
- Subject: [xsl] Converting attributes to elements and preserving the hierarchy
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi all,
I am trying to transform an xml document into a resultant xml where
the attributes of the source are converted to elements and one of the attributes as
the value of the node.(Using Xalan ).
eg for source XML
:
<nfield fldname="DETAILS" >
<nfield fldname="Creation_Date" reserve2="20122001"/>
<nfield fldname="REPEATER_OUTER">
<nfield fldname="Address1"reserve2="SHENTON WAY"/>
<nfield fldname="REPEATER" length="0" fldtype="F">
<nfield fldname="Rate" reserve2="25"/>
</nfield>
</nfield>
</nfield>
I am able to do the transformation but the result doent have the child parent realtionship.
I used the template
<xsl:template match="/">
<xsl:element name="{/template/header/tmplname}">
<xsl:for-each select="/template/format//nfield">
<xsl:element name="{@fldname}">
<xsl:value-of select="@reserve2"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
The result was something like this
<DETAILS/>
<Creation_Date>20122001</Creation_Date>
<REPEATER_OUTER/>
<Address1>SHENTON WAY</Address1>
<REPEATER/>
<RATE>25</RATE>
Actually I need to get
<DETAILS>
<Creation_Date>20122001</Creation_Date>
<REPEATER_OUTER>
<Address1>SHENTON WAY</Address1>
<REPEATER>
<RATE>25</RATE>
</REPEATER>
</REPEATER_OUTER>
</DETAILS>
Where am I going wrong?Can someone please point out the problem.....
thanks
Samuel Abraham
--
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list