[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: is arity-based "polymorphism" safe to use in xsl 2

Subject: RE: is arity-based "polymorphism" safe to use in xsl 2.0 functions?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 28 Feb 2006 15:53:38 -0000
xsl 2
The spec allows you to write this because the designers thought it was
useful, so go ahead and use it.

But I prefer the version at

http://www.w3.org/TR/xpath-functions/#index-of-node


Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Joern Nettingsmeier [mailto:nettings@xxxxxxxxxxxxxxxxxxxxxx]
> Sent: 28 February 2006 14:57
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  is arity-based "polymorphism" safe to use in
> xsl 2.0 functions?
>
> 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,
>
> jvrn
>
> --
> jvrn 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.