[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting attributes to elements and preserving t

Subject: RE: Converting attributes to elements and preserving the hierarchy
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 19 Dec 2001 10:49:58 +0200
RE:  Converting attributes to elements and preserving t
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.