[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: repetition using for-each (and generating "attribu
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|