2010-03-18T13:33:39
Dave Pawson.
link
Home
xslt2
I've been doing some work with Dimitre on his fxsl
library. I wanted to test what I'd done and needed
something to compare the outcome of a function returning
one of those strange xslt2.0 datatypes. Or is it xpath 2
and xquery 1 datatypes? Anyway. I started coding and
stopped when I realised just how long the list was, sure
someone had done it before. I found some work Florent had
done a few years ag at his
website. I tweaked that such that rather than
retaining a type, it created both an element in a rather
long choose statement, then went on to define an xsl
function with a couple of parameters for comparison. I
used Florents file xs-simple-types.xml, since
I haven't paid the annual Saxony tax, and modified
func-copy-make-whens.xsl to do what I
wanted. For example, for the xs:integer datatype I have
<xsl:when test="($n1 instance of xs:integer) and
($n2 instance of xs:integer)">
<xsl:sequence select="d:integer-cmp($n1,$n2)"/>
</xsl:when>
then, for the actual function, I generated
<!-- Compare integer-->
<xsl:function name="d:integer-cmp" as="xs:boolean">
<xsl:param name="n1" as="xs:integer"/>
<xsl:param name="n2" as="xs:integer"/>
<xsl:if test="$debug">
<xsl:message>integer-cmp
<xsl:value-of select="$n1"/>,<xsl:value-of select="$n2"/>
</xsl:message>
</xsl:if>
<xsl:sequence select="$n1 = $n2"/>
</xsl:function>
So I now have a full set of comparisons. The only odd ones are the doubles and floats. I needed to have a three parameter argument list such that I could assert that two values are equal... within a given tolerance. So for double and float types I have a three parameter function using the same logic.
XLST is silly here IMHO. It disallows two user functions to exist with the same name and arity, yet also disallows two functions to exist which have the same name, arity yet different parameter data types. I do hope there's a good reason for this.
If it's any use to you, it is here.
Keywords: xslt2
Comments (View)Return to main index