You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Simon Kitching (JIRA)" <xa...@xml.apache.org> on 2004/11/12 04:53:25 UTC

[jira] Commented: (XALANJ-1719) muenchian grouping + sorting with strange effects

     [ http://nagoya.apache.org/jira/browse/XALANJ-1719?page=comments#action_55387 ]
     
Simon Kitching commented on XALANJ-1719:
----------------------------------------

I also struck this bug in the context of the Muenchian method. 

However the issue is caused by <xsl:sort>; it really alters the order of the elements in the nodelist generated by the parent xsl:for-each statement's select clause.

When the for-each statement's select clause is really an xpath expression, the resulting node-list is only ever used within the body of that for-each statement so the fact it gets altered is no problem.

However when the for-each statement's select clause is a variable reference (eg select="$items") or is an entry in a key (select="key('some-key', ...)") then the effect of the sort persists after the for-each statement completes, which is not good.

SaxonB8 and xerces-j-2.6.0 in XSLTC mode do not suffer from this problem. Xerces-j-2.6.0 in interpretive mode does.

I recommend that whenever <xsl:for-each> has an <xsl:sort> child, the selected nodelist should be cloned before being sorted. An additional optimisation would be to detect whether the select clause was an xpath (ie the nodelist is private) and not bother cloning in that case.

Attached files "in.xml" and "in.xsl" demonstrate this behaviour. They can be run using:
   java -jar xalan.jar -in in.xml -xsl in.xsl  [-xsltc]

> muenchian grouping + sorting with strange effects
> -------------------------------------------------
>
>          Key: XALANJ-1719
>          URL: http://nagoya.apache.org/jira/browse/XALANJ-1719
>      Project: XalanJ2
>         Type: Bug
>   Components: Xalan-interpretive, transformation
>     Versions: 2.5
>  Environment: Operating System: Other
> Platform: Other
>     Reporter: Jörg Heinicke
>     Assignee: Xalan Developers Mailing List
>  Attachments: gump.xml
>
> I try to transform the Cocoon Gump descriptor available at
> http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/gump.xml (simplified version will
> be attached) with a stylesheet to a property file as
> http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/blocks.properties.
> In the stylesheet I group the Cocoon blocks (<project name="cocoon-block-xyz">)
> depending on their @status. The problem is in the following template:
> The stylesheet:
> <xsl:key name="status" match="project[starts-with(@name, 'cocoon-block-')]"
> use="@status"/>
> <xsl:template match="/module">
>     <xsl:apply-templates
>         select="project[starts-with(@name, 'cocoon-block-')]
>                        [count(. | key('status', @status)[1]) = 1]"
>         mode="group"/>
> </xsl:template>
> <xsl:template match="project" mode="group">
> --------
>     <xsl:apply-templates select="key('status', @status)">
>         <xsl:sort select="@name"/>
>     </xsl:apply-templates>
> </xsl:template>
> <xsl:template match="project">
>   <xsl:value-of select="@name"/>
>   <xsl:text>&#10;</xsl:text>
> </xsl:template>
> There are 3 different groups ('stable', 'unstable', 'deprecated'), which should
> result in 3 lines of -------- as long as the elements of one group are not
> sorted. If the above xsl:sort is in use, there are more lines. One further line
> is added if the grouping element (i.e. the one returned by key('status',
> @status)[1]) is not the first one after sorting. With the gump.xml as it is, you
> get 5 lines. If you rename the first project element to cocoon-block-aaaa, you
> will only get 4 lines.
> This happens with Xalan 2.5.2 and seems to be a regression bug.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org