[xsl] EXSL <func:result> returning a node set

Subject: [xsl] EXSL <func:result> returning a node set
From: Nic Ferrier <nferrier@xxxxxxxxxxxxxxxxxxxx>
Date: 23 Sep 2003 13:40:31 +0100
I've got a problem with EXSLT functions, I hope someone will be able
to help me,

I think I managed to get EXSLT's <func:result> to return a node set
but I don't seem able to use predicates on the returned set.

Here's my functions:

   <func:function name="pcpfunc:date">
       <xsl:param name="el"/>
            <xsl:variable name="dateset" select="str:tokenize($el, ', ')"/>
                <xsl:value-of select="$dateset[3]"/>
                <xsl:value-of select="$dateset[1]"/>
                <xsl:if test="$dateset[2] &lt; 10">0</xsl:if><xsl:value-of select="$dateset[2]"/>

   <xsl:template match="*" mode="pcpdatefunc">
       <xsl:copy-of select="pcpfunc:date(.)"/>

   <func:function name="pcpfunc:ordered">
       <xsl:param name="node-set"/>
            <xsl:apply-templates select="$node-set" mode="pcpdatefunc">
                <xsl:sort select="pcpfunc:date(.)" order="descending"/>

The function pcpfunc:ordered is supposed to return the transformed
node set that is passed in, the transformation causes date fields in a
specific format to be translated into a YYYYMMDD format

If one uses it like this:

   <xsl:value-of select="pcpfunc:ordered(/el1/el2/date)"/>

it works correctly, but if you use it like this:

   <xsl:value-of select="pcpfunc:ordered(/el1/el2/date)[1]"/>

Clearly, that should pull off the most recent date. But (with libxml2)
it fails.

I've fixed my immediate problem by having another function, like this:

   <func:function name="pcpfunc:newest">
        <xsl:param name="node-set"/>
             <xsl:apply-templates select="$node-set[1]" mode="pcpdatefunc">
                 <xsl:sort select="pcpfunc:date(.)" order="descending"/>

But it seems a pity to not be able to compose these functions when
dealing with node-sets.

Am I being over-optimistic? Or is it possible? If so: how?

Nic Ferrier

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

Current Thread