Subject: RE: [xsl] Converting attributes to elements and preserving the hierarchy From: "Samuel Abraham" <samuel.abraham@xxxxxx> Date: Wed, 19 Dec 2001 17:20:01 +0800 |
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@xxxxxxxxxxx@lists.mulberrytech.com on 12/19/2001 08:44 AM GMT Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx DELEGATED - Sent by: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Samuel Abraham > Sent: 19 December 2001 07:56 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Converting attributes to , Chris Bayes | Thread | Re: [xsl] Converting attributes to , Steve Muench |
RE: [xsl] Converting attributes to , Jarno . Elovirta | Date | RE: [xsl] General Searching query, Andrew Welch |
Month |