This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: repetition using for-each (and generating "attributes")
- To: Kris Kolodziej <kkolodziej at syncline dot com>
- Subject: Re: [xsl] repetition using for-each (and generating "attributes")
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 23 Jul 2001 17:43:31 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <3B5C2C1F.AA551B34@syncline.com> <3B5C4747.A1B84C33@cylogix.com><3B5C3D8B.68FEDB96@syncline.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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