Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - RE: Grouping by two or any number >Thread Next - RE: Grouping by two or any number RE: Grouping by two or any numberTo: NULL Date: 12/2/2004 8:35:00 AM well that was kool. your first xsl solved my problem.
i am very much interested in the second one but when i validate it give me
the following error..
The character '<' cannot be used in an attribute value. Error processing
resource 'file:///C:/grouping.xsl'. Line 32, Position 69
<xsl:for-each select=". | preceding-sibling::node[position() <=
($group-size - 1)]">
--------------------------------------------------------------------^
Thanks & Regards,
Kiran
"Mukul Gandhi" wrote:
> The following stylesheet can accept any group size..
>
> You may run it as :
> msxsl file.xml file.xsl group-size=4
> (You may pass any value for group-size from the command line)
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:output method="text" />
>
> <xsl:param name="group-size" select="3" />
>
> <xsl:template match="/Parent">
> <xsl:variable name="n" select="count(node) - (floor((count(node) div
> $group-size)) * $group-size)" />
>
> <xsl:for-each select="node">
> <xsl:if test="(position() mod $group-size) = 0">
> group <xsl:value-of select="floor(position() div $group-size)"
> /><xsl:text> - </xsl:text>
> <xsl:for-each select=". | preceding-sibling::node[position() <=
> ($group-size - 1)]">
> <xsl:value-of select="." /><xsl:if test="(position() mod
> $group-size) != 0"><xsl:text>,</xsl:text></xsl:if>
> </xsl:for-each>
> <xsl:text>
> </xsl:text>
> </xsl:if>
> <xsl:if test="((position() = last()) and ((position() mod $group-size)
> != 0))">
> group <xsl:value-of select="floor(position() div $group-size) + 1"
> /><xsl:text> - </xsl:text>
> <xsl:for-each select=". | preceding-sibling::node[position() < $n]">
> <xsl:value-of select="." /><xsl:if test="position() !=
> last()"><xsl:text>,</xsl:text></xsl:if>
> </xsl:for-each>
> <xsl:text>
> </xsl:text>
> </xsl:if>
> </xsl:for-each>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Regards,
> Mukul
>
>
> "Kiran" wrote:
>
> > i have the following xml
> >
> > <Parent>
> > <node>a</node>
> > <node>s</node>
> > <node>d</node>
> > <node>f</node>
> > <node>g</node>
> > <node>h</node>
> > <node>j</node>
> > <node>k</node>
> > <node>l</node>
> > </Parent>
> >
> >
> > Need to print in following format (into groups of two)
> >
> > group 1 - a,s
> > group 2 - d,f
> > group 3 - g,h
> > group 4 - j,k
> > group 5 - l
> >
> > Thanks in advance
> >
> > Kiran
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
