Referring input document when processing multiple documents in XSLT

Discussion in 'XML' started by Filip Hendrickx, Feb 7, 2006.

  1. 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.
     
    Filip Hendrickx, Feb 7, 2006
    #1
    1. Advertising

  2. Filip Hendrickx

    George Bina Guest

    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
     
    George Bina, Feb 7, 2006
    #2
    1. Advertising

  3. Re: Referring input document when processing multiple documents inXSLT

    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>
     
    Joe Kesselman, Feb 7, 2006
    #3
  4. Re: Referring input document when processing multiple documents inXSLT

    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.
     
    Filip Hendrickx, Feb 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SV
    Replies:
    1
    Views:
    628
    Mukul Gandhi
    Aug 16, 2005
  2. Replies:
    4
    Views:
    691
  3. Replies:
    1
    Views:
    493
    Juan T. Llibre
    Oct 18, 2006
  4. Ralph Amissah
    Replies:
    0
    Views:
    196
    Ralph Amissah
    Nov 20, 2005
  5. Christina

    title of referring document

    Christina, Oct 24, 2006, in forum: Javascript
    Replies:
    5
    Views:
    148
    Randy Webb
    Oct 24, 2006
Loading...

Share This Page