xsl-list
[Top] [All Lists]

Re: [xsl] Determine position in node sequence based on criteria

2010-06-30 11:55:10
It would be much cleaner with a higher-order function, which you can write
in XSLT/XPath 2.1:

<xsl:function name="f:index-of" as="xs:integer*">
<xsl:param name="sequence" as="item()*"/>
<xsl:param name="test" as="function(item()) as xs:boolean"/>
<xs:sequence select="for $i in 1 to count(sequence) return
$i[$test($seq[$i])]"/>
</xsl:function>

then

f:index-of(../c, function($c){matches($c, $regex)})



What would be the equivalent of this (possible even in XSLT 2.0) in
XSLT 2.1 / XPath 2.1:

    f:map(f:index-of($seq), $seq[f:someCondition(.)])

f:index-of($seq) is the partial application of f:index-of() on its
first argument.

What name has in F & O 1.1 the f:map() function?


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play


On Wed, Jun 30, 2010 at 7:28 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:

Agreed. It seems like it would be real handy to have position() take
an argument:

 position(../s[])

and return the position of the matching items...

The position of what item in what sequence?

or loosen the
restrictions on position() in a for expression, or have a different
function where you could get the position in a for expression:

for $i in ../s
 if (...) then $i/position() else ()



This all depends on maintaining more context, and we've arguably got too
much context-sensitivity already, especially in XSLT.

It would be much cleaner with a higher-order function, which you can write
in XSLT/XPath 2.1:

<xsl:function name="f:index-of" as="xs:integer*">
<xsl:param name="sequence" as="item()*"/>
<xsl:param name="test" as="function(item()) as xs:boolean"/>
<xs:sequence select="for $i in 1 to count(sequence) return
$i[$test($seq[$i])]"/>
</xsl:function>

then

f:index-of(../c, function($c){matches($c, $regex)})

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--