xsl-list
[Top] [All Lists]

Re: [xsl] can a function return an element of a nodeset

2011-01-13 08:29:38
Well you are right Martin, let's say <bar> can be anywhere in the document and the function returns :
document('foo.xml')//bar[@id='$id']
(supposing id is id type, thus unique)

I tried with a sequence and that's it !

Thanks a lot Martin,
Matthieu.


Le 13/01/2011 15:17, Martin Honnen a écrit :
Matthieu Ricaud-Dussarget wrote:

I'm wondering if there is a way to make a function returning an element
(or a kind of "pointer" to an element) of a another document.
Something like :

<xsl:function name="my:get-node" as="item()*">
<xsl:param name="id"/>
<xsl:copy-of select="document('foo.xml')/bar[@id='$id']"/>

<xsl:sequence select="document('foo.xml')/bar[@id=$id]"/>
returns the node(s) itself(themselves), without copying.

</xsl:function>

The xsl:copy instruction will here copy the node wilthout his contexte,
but I would like to be able to perform xpath test which need the context
of this node within foo.xml, such as :

<xsl:value-of select="count(my:get-node('123')/preceding-sibling::*)"/>

I guess this is not possible, can someone confirm this ?

Well a document has a single root element that can't have any sibling elements so document(...)/bar can't have sibling elements but other than that I think you want to use xsl:sequence.




--
Matthieu Ricaud
IGS-CP
Service Livre numérique



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>