473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

returning to the main input document from XSLT

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
Jul 20 '05 #1
2 1370


Andy Fish wrote:
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:with-param name="primary-root" select="/" />
</xsl:apply-templates>

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

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Martin Honnen <ma*******@yahoo.de> writes:
Andy Fish wrote:
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.

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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christian Roth | last post by:
Hello, when using this "identity" processing sheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="iso-8859-1" /> ...
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
3
by: Filip Hendrickx | last post by:
Hi all. I am processing two documents with an XSLT, one is the input document, the other is loaded with the document() function in a variable $doc2. Inside a template that matches an element...
3
by: msnews.microsoft.com | last post by:
Hi Does anybody know if XSLT can process several XML file at a time I have two xml document which stored in memory stream and wanna to combine it together under several rules. I am tring to...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
3
by: Greg | last post by:
Hi, I want to create a web based interface that uses a form + Javascript (in an XHTML namespace) to construct an XPath to query and modify the attributes of some SVG (in an SVG namespace). ...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
3
by: H. Martins | last post by:
I need to use command line input to a tinny c# application: It goes like this: ** program.cs ** using System; using System.Collections.Generic;
2
by: dutone | last post by:
Is it possible to use a template and then, in the same transformation, reuse it for a call to document()? I have a document that has a child. If necessary, I need to include another document's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.