Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Referring input document when processing multiple documents in XSLT

Reply
Thread Tools

Referring input document when processing multiple documents in XSLT

 
 
Filip Hendrickx
Guest
Posts: n/a
 
      02-07-2006
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="document('doc2.xml')"/>
<xsl:apply-templates select="$doc2/someNodeInDoc2"/>
</xsl:template>

<xsl:template match="someNodeInDoc2">
<xsl:variable name="someNodeInInputDoc" 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/someNodeInInputDoc, but
isn't there a way to directly access the input document, without
explicitly having to load the input document?

Thanks!

Filip Hendrickx.
 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      02-07-2006
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      02-07-2006
Filip Hendrickx wrote:
> I solved the problem by defining an additional variable $inputDoc for
> the input document and then using $inputDoc/someNodeInInputDoc


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="document('doc2.xml')"/>
<xsl:apply-templates select="$doc2/someNodeInDoc2"/>
</xsl:template>

<xsl:template match="someNodeInDoc2">
<xsl:variable name="someNodeInInputDoc"
select="$inputDoc/someNodeInInputDoc"/>
...
</xsl:template>
</xsl:stylesheet>
 
Reply With Quote
 
Filip Hendrickx
Guest
Posts: n/a
 
      02-07-2006
Joe Kesselman schreef:
> Filip Hendrickx wrote:
>> I solved the problem by defining an additional variable $inputDoc for
>> the input document and then using $inputDoc/someNodeInInputDoc

>
> 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="document('doc2.xml')"/>
> <xsl:apply-templates select="$doc2/someNodeInDoc2"/>
> </xsl:template>
>
> <xsl:template match="someNodeInDoc2">
> <xsl:variable name="someNodeInInputDoc"
> select="$inputDoc/someNodeInInputDoc"/>
> ...
> </xsl:template>
> </xsl:stylesheet>


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

Filip.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
title of referring document Christina Javascript 5 10-24-2006 10:44 PM
Including XSLT/XML document within a XSLT document dar_imiro@hotmail.com XML 4 12-13-2005 02:26 AM
[SiSU] book/document generator, sample documents: summary page for document markup and output Ralph Amissah Ruby 0 11-20-2005 03:23 PM
Multiple Input XML documents to produce one output XML SV XML 1 08-16-2005 10:37 AM
returning to the main input document from XSLT Andy Fish XML 2 04-07-2005 06:27 PM



Advertisments