[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: build group of elements
At 2012-06-24 15:41 +0100, henry human wrote:
sorry for my mistake..again the input xml data and the expecting output: The xml data has many foo elements (1000). Just by conjecture, I'm guessing you want <fooGroup> to be three groups of three. You don't explain the criteria, but that is the only "meaningful" interpretation I can see. Next time it would help if you could explain your requirements when including an example rather than make us guess by looking at your example. If I've guessed correctly, this is done easiest with adjacent grouping. I hope this helps. . . . . . . . . . Ken ~/t/ftemp $ cat henry.xml <?xml version="1.0" encoding="UTF-8"?> <xmldata> <ss> s </ss> <nn>n </nn> <foo>tt</foo> <foo>bb</foo> <foo>aa</foo> <foo>mm</foo> <foo>ll</foo> <foo>nn</foo> <foo>ff</foo> <foo>gg</foo> <foo>ii</foo> <hh>h</hh> </xmldata> ~/t/ftemp $ xslt2 henry.xml henry.xsl <?xml version="1.0" encoding="UTF-8"?> <fooGroup> <_1st_element> <_1st_element>tt</_1st_element> <_2nd_element>bb</_2nd_element> <_3rd_element>aa</_3rd_element> </_1st_element> <_2nd_element> <_1st_element>mm</_1st_element> <_2nd_element>ll</_2nd_element> <_3rd_element>nn</_3rd_element> </_2nd_element> <_3rd_element> <_1st_element>ff</_1st_element> <_2nd_element>gg</_2nd_element> <_3rd_element>ii</_3rd_element> </_3rd_element> </fooGroup>~/t/ftemp $ ~/t/ftemp $ cat henry.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:h="urn:X-henry" exclude-result-prefixes="h" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="xmldata"> <xsl:for-each-group select="foo" group-adjacent="(position()-1) idiv 9"> <fooGroup> <xsl:for-each-group select="current-group()" group-adjacent="(position()-1) idiv 3"> <xsl:element name="_{h:ord(position())}_element"> <xsl:for-each select="current-group()"> <xsl:element name="_{h:ord(position())}_element"> <xsl:copy-of select="node()"/> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each-group> </fooGroup> </xsl:for-each-group> </xsl:template> <xsl:function name="h:ord"> <xsl:param name="pos"/> <xsl:number value="$pos" ordinal="1"/> </xsl:function> </xsl:stylesheet> ~/t/ftemp $
|
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
|