Hi,
For my XSLT 2 processor, https://github.com/egh/xjslt, I would like to fix the implementation of last() and position(). The behavior is a little tricky, though.
For instance, this stylesheet:
<?xml version="1.0" encoding="UTF-8" ?>
<t:transform xmlns:t="http://www.w3.org/1999/XSL/Transform" version="2.0">
<t:template match="/">
<out>
<t:for-each select="/doc/foo">
<t:value-of select="position()"/>
</t:for-each>
</out>
</t:template>
</t:transform>
when applied to:
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<foo/><bar/>
<foo/><bar/>
<foo/><bar/>
</doc>
should output:
<?xml version="1.0" encoding="UTF-8"?><out>123</out>
In contrast, for instance, the stylesheet:
...
<t:for-each select="/doc/element()">
<t:if test="local-name() = 'foo'">
<t:value-of select="position()"/>
</t:if>
</t:for-each>
would output 135. In other words, the position() (and last()) depend on the for-each xpath and what was selected there.
In order to do this with my implementation, I need to either be able:
- to pass in something to
evaluateXPath* functions to override the dynamicContext.contextSequence, or
- to override the
position() and last() functions in some cases, i.e. when the contextItem is the same as the contextNode I passed in (and so I can calculate these values based on the node set being processed). But this means both:
a. I need access to the contextItem and:
b. Ideally, I need to pass computation to the built in implementation if the contextItem is not the contextNode I passed in.
- something else that I haven't thought of?
(1) is probably the easiest solution from my point of view, but I don't know if this is feasible.
I am happy to implement a solution to this, but I wanted to get a sense of what the best solution might be.
Thank you for your help! Let me know what other info might help you.
Hi,
For my XSLT 2 processor, https://github.com/egh/xjslt, I would like to fix the implementation of
last()andposition(). The behavior is a little tricky, though.For instance, this stylesheet:
when applied to:
should output:
In contrast, for instance, the stylesheet:
would output
135. In other words, theposition()(andlast()) depend on thefor-eachxpath and what was selected there.In order to do this with my implementation, I need to either be able:
evaluateXPath*functions to override thedynamicContext.contextSequence, orposition()andlast()functions in some cases, i.e. when thecontextItemis the same as thecontextNodeI passed in (and so I can calculate these values based on the node set being processed). But this means both:a. I need access to the
contextItemand:b. Ideally, I need to pass computation to the built in implementation if the
contextItemis not thecontextNodeI passed in.(1) is probably the easiest solution from my point of view, but I don't know if this is feasible.
I am happy to implement a solution to this, but I wanted to get a sense of what the best solution might be.
Thank you for your help! Let me know what other info might help you.