Subject: RE: [xsl] Converting attributes to elements and preserving the hi erarchy From: Jarno.Elovirta@xxxxxxxxx Date: Wed, 19 Dec 2001 10:49:58 +0200 |
Hip hei! > 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 You're processing all nfield elements separately. You could try e.g. <xsl:template match="/"> <xsl:element name="{/template/header/tmplname}"> <!-- process the nfields that don't have an nfield parent --> <xsl:apply-templates select="/template/format//nfield[not(parent::nfield)]" /> </xsl:element> </xsl:template> <xsl:template match="nfield"> <xsl:element name="{@fldname}"> <xsl:value-of select="@reserve2"/> <!-- you have to process the containing nfields here --> <xsl:apply-templates select="nfield" /> </xsl:element> </xsl:template> You didn't show the whole source document, so /template/format//nfield[not(parent::nfield)] might not apply to the real source, but I hope you get the idea. Hope this helps, Santtu XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Converting attributes to , Wendell Piez | Thread | [xsl] document() merge DISTINCT, Alex Schuetz |
RE: [xsl] Converting attributes to , Chris Bayes | Date | RE: [xsl] Converting attributes to , Samuel Abraham |
Month |