This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: 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 17:20:01 +0800
- Subject: RE: [xsl] Converting attributes to elements and preserving the hierarchy
- Reply-to: xsl-list at lists dot mulberrytech dot com
hi,
Thanks.It worked.I started with XSLT just 2 days back.
So excuse me if some obvious links or documents clearly states the answer to the question below.
How do I decide when to use <xsl:for-each> or a template ?
regds
Samuel Abraham
---------------------------------------- Message History ----------------------------------------
From: chris@bayes.co.uk@lists.mulberrytech.com on 12/19/2001 08:44 AM GMT
Please respond to xsl-list@lists.mulberrytech.com
DELEGATED - Sent by: owner-xsl-list@lists.mulberrytech.com
To: xsl-list@lists.mulberrytech.com
cc:
Subject: RE: [xsl] Converting attributes to elements and preserving the hierarchy
Beginners rule #1 Never use for-each. By using for-each here you are
flattening you data. Use a template instead
<xsl:template match="nfield">
<xsl:element name="{@fldname}">
<xsl:apply-templates />
<xsl:value-of select="@reserve2"/>
</xsl:element>
</xsl:template>
Ciao Chris
XML/XSL Portal
http://www.bayes.co.uk/xml
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Samuel Abraham
> Sent: 19 December 2001 07:56
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] Converting attributes to elements and
> preserving the hierarchy
>
>
> 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
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
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