[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: "Chris Bayes" <chris@xxxxxxxxxxx>
Date: Wed, 19 Dec 2001 08:44:27 -0000
converting attributes to elements
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:  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


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.