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

Re: repetition using for-each (and generating "attribu

Subject: Re: repetition using for-each (and generating "attributes")
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 23 Jul 2001 17:43:31 +0100
repetition using xslt
Hi Kris,

> OK! Thanks to everyone - I modified your suggestion and it worked.
> This is what I used:
>
> <RING>
>         <xsl:for-each select="//Polygon/Point">
>                 <POINT>
>                 <xsl:attribute name="x">
>                         <xsl:value-of select="@x"/>
>                 </xsl:attribute>
>                 <xsl:attribute name="y">
>                         <xsl:value-of select="@y"/>
>                 </xsl:attribute>
>                </POINT>
>         </xsl:for-each>
>     </RING>

>From the looks of your source XML as quoted, you have only one Polygon
element within it, which is the document element. In that case,
there's no need to use // at the beginning of the path - using // will
make the XSLT processor search all the way through the entire XML
document to find Polygon elements, while you know exactly where it is.
So you could simplify to:

<RING>
  <xsl:for-each select="/Polygon/Point">
    <POINT>
      <xsl:attribute name="x">
        <xsl:value-of select="@x"/>
      </xsl:attribute>
      <xsl:attribute name="y">
        <xsl:value-of select="@y"/>
      </xsl:attribute>
    </POINT>
  </xsl:for-each>
</RING>

The other simplification that you could make is to either use
attribute value templates to create the attributes:

<RING>
  <xsl:for-each select="/Polygon/Point">
    <POINT x="{@x}" y="{@y}" />
  </xsl:for-each>
</RING>

Or, since you're keeping the same names and values for the attributes,
you could simply copy them with:

<RING>
  <xsl:for-each select="/Polygon/Point">
    <POINT>
      <xsl:copy-of select="@x | @y" />
    </POINT>
  </xsl:for-each>
</RING>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.