[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] libxslt version changes RTF or exsl node-set sorting behavior


Subject: [xsl] libxslt version changes RTF or exsl node-set sorting behavior
From: Paul Kissman <pkissman@xxxxxxxxxxxxxx>
Date: Fri, 30 Jan 2004 15:10:39 -0500 (EST)

I have an xsl stylesheet that behaves the way I need it to using
libxslt-1.0.10, but not on a different machine using version 1.0.32. 

The stylesheet puts a result tree fragment into a variable in sorted
order, so that I can later turn the RTF into a node-set and iterate
through the nodes in alphabetical order. 

I need the sorting done up front because I am creating a table using the
following-sibling::* axis methodology recommended in the XSLT FAQ for
table creation (http://www.dpawson.co.uk/xsl/sect2/N7450.htm), and
following-siblings have to be in the right order.

Near the top of the stylesheet I create an RTF of unique subject headings
in alpha order:

<xsl:variable name="subject_tree">
                <xsl:for-each
select="//subject[not(.=preceding::subject)]">
                        <xsl:sort/>
                        <xsl:copy-of select="."/>
                </xsl:for-each>
</xsl:variable>


Then further down in the stylesheet, I use exslt to turn the RTF into a
node-set...

<!-- Create a table of unique Subject Headings in sorted order-->
<table>
<xsl:for-each select="exsl:node-set($subject_tree)/*">
	<xsl:variable name="pos" select="position()"/>
	<xsl:for-each select="self::node()[$pos mod 6 = 1]">
		<tr>
			<xsl:apply-templates select=". |
following-sibling::*[position() &gt;= 1 and position() &lt; 6
]" mode="NewHeaderTOC">
		</xsl:apply-templates>
		</tr>
	</xsl:for-each>
</xsl:for-each>
</table>

So, I am creating a table that is 6 cells wide and an indeterminate number
of rows, with one node from the listing of subjects in each
cell.  Again, the
order of the subjects should be alphabetical.

So the output would look something like:

<table>
<tr>
<td>Arts &amp; Humanities</td></tr>
<td>Business</td>
...
[ 6 columns total ]
...
</tr>
<tr>
<td>Medicine</td>
<td>Social Sciences</td>
...
</tr>
</table>

Here is a sample of the xml structure.

<databases>
	<database display="true" code="Gale_BioRC">
		<name>Biography Resource Center w/ Marquis Who&#8217;s
Who</name>

<url>http://infotrac.galegroup.com/itweb/GALE_LOCATION?db=BioRC</url>
			...
			...
			<subjects>
            		<subject>Arts &amp; Humanities</subject>
				<subject>General</subject>
				<subject>Science
&amp; Technology</subject>
				<subject>Social Sciences</subject>
			</subjects>
	</database>
	<database_family>  <!-- a different grouping level than above-->
		<database>
			...
			<subjects>
				<subject>General</subject>
				<subject>Encyclopedias</subject>
			</subjects>
		</database>
	</database_family>
</databases>

This all works fine on our current server and though it may not be
elegant, I have no complaints.

The problem arises because we are moving to a newer web server which has
libxslt-1.0.32 (SUSE RPM) installed, and I find that though <xsl:sort/>
apparently sorts properly when I create the variable RTF
($subject_listing) and look at its contents, the <xsl:apply-templates
select=". | following-sibling::*[position()... is paying no attention at
all once it has been turned into a node-set.

And if I put an <xsl:sort/> under the first <xsl:foreach> tag when
iterating through the new node-set, the following-sibling::* ignores that
order as well (which doesn't surprise me).

Is the internal ordering of the node-set that I create from the RTF
completely uncontrolled? Should I be creating the variable
$subject_listing a different way?

Suggestions and explanations would be appreciated. I didn't see anything
in the change log or in any FAQs to explain this change in behavior. But
maybe I am looking in the wrong place.

Sincerely,

Paul J. Kissman
Library Information Systems Specialist
Massachusetts Board of Library Commissioners
648 Beacon St.
Boston, MA  02215
paul.kissman@xxxxxxxxxxx
www.mlin.lib.ma.us or www.mlin.org
617-267-9400  800-952-7403 (in-state)
Fax: 617-421-9833



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords