[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Xalan bug?

Subject: Re: Xalan bug?
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 2 Dec 2004 10:40:36 -0800 (PST)
xalan position
I have added some comments in my logic(shown below) to
help in understanding..

<?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">
   <!-- calculate the no of "node" elements, which are
left as a fraction; which are to be displayed in the
last group -->
   <xsl:variable name="n" select="count(node) -
(floor((count(node) div $group-size)) * $group-size)"
/>
   
   <xsl:for-each select="node">
     <!-- determine group boundary; this if test stops
at the last "node" element of the group -->
     <xsl:if test="(position() mod $group-size) = 0">
       group <xsl:value-of select="floor(position()
div $group-size)" /><xsl:text> - </xsl:text>
       <!-- display group members -->
       <xsl:for-each select=". |
preceding-sibling::node[position() &lt;= ($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>&#xa;</xsl:text>
     </xsl:if> 
     <!-- this if test processes the last group; whose
number of group members will be less than the
group-size -->
     <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() &lt; $n]">
         <xsl:value-of select="." /><xsl:if
test="position() !=
last()"><xsl:text>,</xsl:text></xsl:if> 
       </xsl:for-each>
       <xsl:text>&#xa;</xsl:text>
     </xsl:if>
   </xsl:for-each>
</xsl:template>
   
</xsl:stylesheet>

I would be happy to see any discussion on this post..

Regards,
Mukul

PS: I have posted it as a bug on Xalan site. 

--- Mukul Gandhi <mukul_gandhi@xxxxxxxxx> wrote:

> 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() &lt;=
> ($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() &lt; $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 - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.