[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
hi !
since it needs to keep an internal counter, i have solved it like this:
regards,
jC6rn
[xsl] is arity-based "polymorphism" safe to use in xsl 2.0 functions?
Subject: [xsl] is arity-based "polymorphism" safe to use in xsl 2.0 functions? From: Joern Nettingsmeier <nettings@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 28 Feb 2006 15:57:26 +0100 |
hi !
since the built-in position() function is awkward in some cases, i wrote a little helper positionInContext($haystack, $needle) that will tell you the position of $needle within $haystack.
since it needs to keep an internal counter, i have solved it like this:
<!-- this is the "internal" function: --> <xsl:function name="r2c:positionInContext" as="xs:integer"> <xsl:param name="haystack" as="node()*"/> <xsl:param name="needle" as="node()"/> <xsl:param name="position" as="xs:integer"/> <xsl:choose> <!-- found? --> <xsl:when test="$needle is $haystack[1]"> <xsl:sequence select="$position"/> </xsl:when> <!-- haystack empty? --> <xsl:when test="not($haystack[2])"> <xsl:sequence select="0"/> </xsl:when> <!-- try next node in haystack: --> <xsl:otherwise> <xsl:sequence select=" r2c:positionInContext( $haystack[position() gt 1], $needle, $position + 1)" /> </xsl:otherwise> </xsl:choose> </xsl:function>
<!-- this is the "API" function: --> <xsl:function name="r2c:positionInContext" as="xs:integer"> <xsl:param name="haystack" as="node()*"/> <xsl:param name="needle" as="node()"/> <xsl:sequence select="r2c:positionInContext($haystack, $needle, 1)"/> </xsl:function>
i know that xsl functions are not polymorphic as to datatypes, but the spec says they are wrt number of arguments. i wonder: is this sort of programming style ok, or am i stretching the spec? saxon processes it just fine.
regards,
jC6rn
-- jC6rn nettingsmeier
home://germany/45128 essen/lortzingstr. 11/ http://spunk.dnsalias.org phone://+49/201/491621
if you are a free (as in "free speech") software developer and you happen to be travelling near my home, drop me a line and come round for a free (as in "free beer") beer. :-D
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Job Posting - XSLT programmer, B Tommie Usdin | Thread | RE: [xsl] is arity-based "polymorph, Michael Kay |
Re: [xsl] <xs:any> and [!CDATA{ - S, Pedro Alves | Date | [xsl] problem adding namespace node, Majirus FANSI |
Month |
Keywords