RE: Returning source document nodes

 

 

  _____  

From: public-qt-comments-request@w3.org
[mailto:public-qt-comments-request@w3.org] On Behalf Of Matthew Fuchs
Sent: 12 March 2004 19:08
To: public-qt-comments@w3.org
Subject: Returning source document nodes

 

I'm trying to understand if it is possible to use <xsl:sequence> to return
nodes, specifically elements, from the source document.  

 

Yes, it is possible.

 

Without getting into the use case behind this, I read both the latest public
working draft and the current working draft as saying that in the following:

 

<xsl:variable name="foo" select="somepath"/>

 

and 

 

<xsl:variable name="foo">

   <xsl:sequence select="somepath"/>

</xsl:variable>

 

$foo will be assigned equivalent nodes from the source document (in
particular, if the result is some descendant of the root, then I can apply
parent or ancestor axes and get the same results).

 

No: the latter case constructs a temporary tree. To return a value from the
source document, you need an "as" attribute, thus:

 

<xsl:variable name="foo" as="element()*">

  <xsl:sequence select="somepath"/>

</xsl:variable>

 

  If that's the case, is it further the case (here's the real interesting
part) that I can put the <xsl:sequence> in a template, i.e.,

 

<xsl:variable name="foo">

    <xsl:apply-templates select="." mode="test"/>

</xsl:variable>

 

<xsl:template match=".element." mode="test">

    <xsl:sequence select="somepath"/>

</xsl:template>

 

and, once again, get back an equivalent node?

 

Yes, you can do this. Again, you need the "as" attribute on xsl:variable.

 

Michael Kay

(I'm not proposing to treat this enquiry as a formal comment on the
specification unless you ask me to do so.)

 

Thank you,

 

Matthew Fuchs

Received on Friday, 12 March 2004 14:57:47 UTC