returning to the main input document from XSLT

A

Andy Fish

Say I am in an XSLT template with the context node set to a node from an
alternative document (i.e. read by the document() function). Is there any
way to select nodes from the original document again?

e.g.

<xsl:template match="foo">
<xsl:apply-templates select="document(doc.xml)" mode="otherdoc" />
</xsl:template>

<xsl:template match="bar" mode="otherdoc">
now my context node is a node in doc.xml. how can I select a node from the
main document?
</xsl:template>

Andy
 
M

Martin Honnen

Andy said:
Say I am in an XSLT template with the context node set to a node from an
alternative document (i.e. read by the document() function). Is there any
way to select nodes from the original document again?

e.g.

<xsl:template match="foo">
<xsl:apply-templates select="document(doc.xml)" mode="otherdoc" />

You could pass a parameter with the main root node (or any other nodes
you want to pass) e.g.
<xsl:apply-templates select="document(doc.xml)" mode="otherdoc">
<xsl:template match="bar" mode="otherdoc">

<xsl:template match="/" mode="otherdoc">
<xsl:param name="primary-root" />
<!-- access $primary-root or descendants e.g.
$primary-root/* here
-->
</xsl:template>
 
D

David Carlisle

Martin Honnen said:
You could pass a parameter with the main root node (or any other nodes
you want to pass) e.g.


or (simpler) define
<xsl:variable name="origroot" select="/"/>
as a global variable outside any template then it is available in all
templates without having to be explictly passed from one to the other.

If there are lots of documents and nested calls from one to the other
then of course you do need to explictly pass parameters with the nodes
giving the right context and Martin's more general solution is your
friend in that case.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top