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

RE: XML Elements to XML Attributes

Subject: RE: XML Elements to XML Attributes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 14 Jan 2007 23:33:24 -0000
RE:  XML Elements to XML Attributes
Using a for-each and testing position() seems clumsy, compared with explicit
indexing. 

What's wrong with

<entry tag="{td[1]}" attribute="{td[2]}" type="{td[3]}"
description="{td[4]}"/>

Not coming from a C/C++ world, I can't see why you would want to use
variables.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Mathieu Malaterre [mailto:mathieu.malaterre@xxxxxxxxx] 
> Sent: 14 January 2007 01:32
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XML Elements to XML Attributes
> 
> Hello,
> 
>   I have a very simple question. I have currently the 
> following xsl script (1). But instead of creating elements I 
> would like to create attributes, something like:
> 
>   <entry tag="{$1}" attribute="{$2}" type="{$3}" description="{$4}"/>
> 
>   Where $1-4 are the values coming from the loop at 
> position() respectively 1-4.
>   Coming from a C/C++ world I would have created variables, 
> unfortunately I cannot do that with the loop. I must be 
> missing something trivial to be able to rewrite it correctly in XSL.
> 
> Thanks
> 
> 
> (1)
>         <entry>
>         <xsl:for-each select="td">
>           <xsl:variable name="cur_val">
>             <xsl:value-of select="."/>
>           </xsl:variable>
>           <xsl:choose>
>             <xsl:when test="position() = 1">
>               <tag d="{$cur_val}"/>
>             </xsl:when>
>             <xsl:when test="position() = 2">
>               <attribute d="{$cur_val}"/>
>             </xsl:when>
>             <xsl:when test="position() = 3">
>               <type d="{$cur_val}"/>
>             </xsl:when>
>             <xsl:when test="position() = 4">
>               <description d="{$cur_val}"/>
>             </xsl:when>
>             <xsl:otherwise>
>               <bug/>
>             </xsl:otherwise>
>           </xsl:choose>
>         </xsl:for-each>
>         </entry>
> 
> 
> --
> Mathieu

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.