Subject: Re: Designs for XSLT functions (Was: Re: [xsl] RE: syntax sugar for call-template) From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 20 Feb 2001 10:03:00 +0000 |
Hi Mike, >> Perhaps xsl:for-each shouldn't be allowed directly within function >> definitions? Can anyone come up with a use case where it's helpful to >> have it? > > Saxon allows xsl:for-each with saxon:function, but doesn't allow > saxon:return within xsl:for-each. Did you see the use cases that I put forward where it could be useful?: --- Firstly, as we know, key() and id() are restricted to finding nodes in the current tree. If I want to use an extension function that retrieves keyed nodes in a particular document then I need to be able to do: <exsl:function name="my:key"> <xsl:param name="key-name" /> <xsl:param name="key-value" /> <xsl:param name="file-name" /> <xsl:param name="base-node" select="/" /> <xsl:for-each select="document($file-name, $base-node)"> <exsl:result select="key($key-name, $key-value)" /> </xsl:for-each> </exsl:function> Another example is if I want to use the built-in sort algorithms to find, for example, the first value alphabetically in a node set: <exsl:function name="my:first-alphabetical"> <xsl:param name="nodes" /> <xsl:for-each select="$nodes"> <xsl:sort /> <xsl:if test="position() = 1"> <exsl:result select="." /> </xsl:if> </xsl:for-each> </exsl:function> --- What do you think? > Use case, turning a node-set into a comma-separated list of the > string-values of the nodes: > > xsl:function name="csv" > xsl:param name="nodeset"/ > xsl:variable name="tree" > xsl:for-each select="$nodeset" > xsl:value-of select="." > xsl:if test="position()!=last" > , > /xsl:if > /xsl:for-each > /xsl:variable > xsl:return select="string($tree)"/ > /xsl:function Ahh, but this shows an xsl:for-each within an xsl:variable. I think that David Rosenborg agrees that that should be allowed - he's only objecting to allowing anything but xsl:param, xsl:variable and exsl:result (or exsl:return) directly within exsl:function. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Designs for XSLT functions (Was, Michael Kay | Thread | Re: Designs for XSLT functions (Was, Uche Ogbuji |
Re: [xsl] intersection revisited, Francis Norton | Date | Re: [xsl] 2.0 feature request, Eric van der Vlist |
Month |