473,804 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referring input document when processing multiple documents in XSLT

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 from $doc2, I need to check a
value from the original input document. However, inside this template,
the context is $doc2. What XPath expression should I use to refer to the
input document? I've tried using /inputNamespace: inputElement, where
inputNamespace and inputElement refer to the input document. This
doesn't work because no such element exists within the context of the
template, which is $doc2.

A small example may clarify want I mean :-).

<xsl:stylesheet >
<xsl:template match="/">
<xsl:variable name="doc2" select="documen t('doc2.xml')"/>
<xsl:apply-templates select="$doc2/someNodeInDoc2"/>
</xsl:template>

<xsl:template match="someNode InDoc2">
<xsl:variable name="someNodeI nInputDoc" select="XPath expression
referring input document"/>
...
</xsl:template>
</xsl:stylesheet>

I solved the problem by defining an additional variable $inputDoc for
the input document and then using $inputDoc/someNodeInInput Doc, but
isn't there a way to directly access the input document, without
explicitly having to load the input document?

Thanks!

Filip Hendrickx.
Feb 7 '06 #1
3 1960
Hi Filip,

The solution is exactly what you used to solve the problem: define a
variable to point to the initial document and use that to access
information in that document.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Feb 7 '06 #2
Filip Hendrickx wrote:
I solved the problem by defining an additional variable $inputDoc for
the input document and then using $inputDoc/someNodeInInput Doc


I think a global variable set to reference the root of the main input
document really is your best solution. This will get set at stylesheet
startup, so it's nearly as efficient as if there was an XSLT built-in
function for this purpose.

<xsl:stylesheet >
<xsl:variable name="inputDoc" select="/"/>

<xsl:template match="/">
<xsl:variable name="doc2" select="documen t('doc2.xml')"/>
<xsl:apply-templates select="$doc2/someNodeInDoc2"/>
</xsl:template>

<xsl:template match="someNode InDoc2">
<xsl:variable name="someNodeI nInputDoc"
select="$inputD oc/someNodeInInput Doc"/>
...
</xsl:template>
</xsl:stylesheet>
Feb 7 '06 #3
Joe Kesselman schreef:
Filip Hendrickx wrote:
I solved the problem by defining an additional variable $inputDoc for
the input document and then using $inputDoc/someNodeInInput Doc


I think a global variable set to reference the root of the main input
document really is your best solution. This will get set at stylesheet
startup, so it's nearly as efficient as if there was an XSLT built-in
function for this purpose.

<xsl:stylesheet >
<xsl:variable name="inputDoc" select="/"/>

<xsl:template match="/">
<xsl:variable name="doc2" select="documen t('doc2.xml')"/>
<xsl:apply-templates select="$doc2/someNodeInDoc2"/>
</xsl:template>

<xsl:template match="someNode InDoc2">
<xsl:variable name="someNodeI nInputDoc"
select="$inputD oc/someNodeInInput Doc"/>
...
</xsl:template>
</xsl:stylesheet>


Now, why did I overlook this simple and elegant solution ;-)? Thanks!

Filip.
Feb 7 '06 #4

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

Similar topics

2
1443
by: enyetor | last post by:
I'm migrating data into a content management system and in order to use the import tool provided I need to change the format of a large xml file and convert each entry to a seperate xml file. This is what I have now: <?xml version="1.0" encoding="UTF-8" ?> <dataroot xmlns:od="urn:schemas-microsoft-com:officedata"
3
1727
by: David Blickstein | last post by:
Hi, I have a Schema and a number of different XSLT stylesheets to translate to different things. One stylesheet translates it to HTML. I'd like to generate the XML files such that when loaded by a browser they are automatically translated into XML and I've accomplished that by inserting the following processing instruction when I generate the file: <?xml:stylesheet type="text/xsl" href="toHtml.xslt" version="1.0"?>
0
1089
by: Chris | last post by:
(cross posted to Xalan-users list) Forgive me if this had been discussed before. I'm currently using Xalan for my xml translations and... I'd like to be able to access multiple in-memory documents (ie DOM) via the document function. Something like document('dom://input2') or the like. I was wondering if there was some extention or vodoo magic in order to accomplish this.
4
9458
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
4
4820
by: Asbjørn Ulsberg | last post by:
Sorry for posting to a lot of groups, but I'm not sure what this problem relates to, so I thought it was better to be safe than sorry. Please feel free to set FUT to the proper group when answering. I'm having problems with the XSLT function 'document()' after upgrading to ASP.NET 1.1. I've started using XmlUrlResolver in the xslt.Transform() method, but it doesn't seem to help in all cases.
3
5395
by: Richard Fritzler | last post by:
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the webuser to select the template, merge his DB record, and produce a formatted document that can be printed or downloaded. We need to do this without specialized software on the client, since it will be universally available to webusers. We...
6
3878
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who use laptops. They have Access databases on their laptops and the data is replicated. The idea is that each case worker would scan their own documents, either remotely or back at the office. And NO I am not planning to store the scanned...
3
1459
by: sql_er | last post by:
Guys, I have a very large XML document. When I query it, it takes too long to produce results. I read somewhere that XML documents could be indexed (althgough that "somewhere" did not describe how exactly). Can someone tell me how it can be done?
2
3051
by: groo78 | last post by:
Hi, I have an XML document that I need to convert to XHTML and I would like to use XSLT. I have attempted transformations using javascript and it works fine. The problem I have is that I need to transform my XML document into multiple DIVs which I can access individually and place in different locations around my page. Is it better to use Javascript DOM and parse the XML document into several smaller XML documents and transform them...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.