Subject: [xsl] Xalan bug? From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Thu, 2 Dec 2004 01:55:02 -0800 (PST) |
Hello, I was solving a problem posted by a user at microsoft.public.xsl newsgroup. I seem to have been hit by a Xalan bug(Xalan-J 2.6.0), which I wish to confirm with members here.. The problem posted was - Subject: Grouping by two or any number -------------------------------------- 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 I wrote the following stylesheet - <?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> I invoke Xalan like this: java org.apache.xalan.xslt.Process -in file.xml -xsl file.xsl -PARAM group-size 2 The output is fine for -PARAM group-size values of 1,2,3 & 4. But for -PARAM group-size values of 5 and above, the ouput is not coming as expected. For e.g., for -PARAM group-size 5, the output received is - group 1 - a,s,d,f,g group 2 - h, I tested the same XSL with Saxon-SA 8.1.1 and MSXSL 4, and both produce correct result for all the cases. Both Saxon and MSXSL produce the following output for group-size=5 - group 1 - a,s,d,f,g group 2 - h,j,k,l Does this look like a Xalan bug? Regards, Mukul __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Complex for-each comparis, Sven Waibel | Thread | RE: [xsl] Xalan bug?, Arun Sinha |
Re: [xsl] Complex for-each comparis, Sven Waibel | Date | Re: [xsl] Complex for-each comparis, David Carlisle |
Month |