Please can someone give me a sample xsl to output a complete element in a for-each loop? For example I'd like to sort the output on <level> by the <sort> value, but as you can see, the elements underneath the <level> node may vary : <root> <level> <sort>2</sort> <x></x> <y></y> </level> <level> <sort>1</sort> <x></x> <a></a> </level> <level> <sort>3</sort> <c></c> <d></d> <e></e> </level> </root> Expected output: <root> <level> <sort>1</sort> <x></x> <a></a> </level> <level> <sort>2</sort> <x></x> <y></y> </level> <level> <sort>3</sort> <c></c> <d></d> <e></e> </level> </root> Thanks - I'm sure it's a doddle for someone here.
On Jul 2, 2:38 am, sbparsons wrote: > Please can someone give me a sample xsl to output a complete element in a > for-each loop? > For example I'd like to sort the output on <level> by the <sort> value, but > as you can see, the elements underneath the <level> node may vary : > <root> > <level> > <sort>2</sort> > <x></x> > <y></y> > </level> > <level> > <sort>1</sort> > <x></x> > <a></a> > </level> > <level> > <sort>3</sort> > <c></c> > <d></d> > <e></e> > </level> > </root> > > Expected output: > <root> > <level> > <sort>1</sort> > <x></x> > <a></a> > </level> > <level> > <sort>2</sort> > <x></x> > <y></y> > </level> > <level> > <sort>3</sort> > <c></c> > <d></d> > <e></e> > </level> > </root> > > Thanks - I'm sure it's a doddle for someone here. Hi, <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform"> <xsl:template match="root"> <xsl:copy> <xsl:for-each select="level"> <xsl:sort select="sort" data-type="number"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:copy> </xsl:template> </xsl:stylesheet> Regards, Balaji. M sql-ebooks.blogspot.com
Thanks for that. The time differences are to blame for the delay in responding to you! Regards. "msbalaji" wrote: > On Jul 2, 2:38 am, sbparsons > wrote: > > Please can someone give me a sample xsl to output a complete element in a > > for-each loop? > > For example I'd like to sort the output on <level> by the <sort> value, but > > as you can see, the elements underneath the <level> node may vary : > > <root> > > <level> > > <sort>2</sort> > > <x></x> > > <y></y> > > </level> > > <level> > > <sort>1</sort> > > <x></x> > > <a></a> > > </level> > > <level> > > <sort>3</sort> > > <c></c> > > <d></d> > > <e></e> > > </level> > > </root> > > > > Expected output: > > <root> > > <level> > > <sort>1</sort> > > <x></x> > > <a></a> > > </level> > > <level> > > <sort>2</sort> > > <x></x> > > <y></y> > > </level> > > <level> > > <sort>3</sort> > > <c></c> > > <d></d> > > <e></e> > > </level> > > </root> > > > > Thanks - I'm sure it's a doddle for someone here. > > Hi, > > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ > Transform"> > <xsl:template match="root"> > <xsl:copy> > <xsl:for-each select="level"> > <xsl:sort select="sort" data-type="number"/> > <xsl:copy-of select="."/> > </xsl:for-each> > </xsl:copy> > </xsl:template> > </xsl:stylesheet> > > Regards, > Balaji. M > sql-ebooks.blogspot.com > >