returning to the main input document from XSLT

Discussion in 'XML' started by Andy Fish, Apr 7, 2005.

  1. Andy Fish

    Andy Fish Guest

    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
    Andy Fish, Apr 7, 2005
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Apr 7, 2005
    #2
    1. Advertising

  3. Martin Honnen <> 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
    David Carlisle, Apr 7, 2005
    #3
    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. John M
    Replies:
    1
    Views:
    1,114
    Kumar Reddi
    May 29, 2005
  2. Replies:
    4
    Views:
    654
  3. Filip Hendrickx
    Replies:
    3
    Views:
    792
    Filip Hendrickx
    Feb 7, 2006
  4. Hal Styli
    Replies:
    14
    Views:
    1,614
    Old Wolf
    Jan 20, 2004
  5. Frederick Ding

    int main() or int main(void)?

    Frederick Ding, Dec 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    639
Loading...

Share This Page