XPath and document() function - backwards

Discussion in 'XML' started by Martin Honnen, May 26, 2004.

  1. Boris Pöhlmann wrote:


    > I have a problem while trying to refer from a file called by the
    > document function to the document where it was called from. I give an
    > example:
    >
    > <filelist>
    > <file name="whatever">
    > <url>foo/bar/somefile.xml</url>
    > </file>
    > <!-- ... -->
    > </filelist>
    >
    > Now I call this template:
    >
    > <xsl:template match="filelist">
    > <xsl:for-each select="file">
    > <xsl:apply-templates select="document(url)//xyz"/>


    Consider using
    <xsl:call-template name="templateName">
    <xsl:with-param name="fileName" select="@name" />
    <xsl:with-param name="xyz" select="document(url)//xyz" />

    > </xsl:for-each>
    > </xsl:template>
    >
    > Now I want the "xyz" template to get the "name" value of "file". I
    > tried the following (with Saxon 7.9.1), but apparently I can't reach
    > out of the document that has been called with "document()".
    >
    > <xsl:template match="xyz"
    > <!-- do some stuff -->
    > <xsl:value-of select="ancestor::file/@name"/>
    > </xsl:template>


    and then here
    <xsl:template name="templateName">
    <xsl:param name="fileName" />
    <xsl:param name="xyz" />
    do some stuff
    <xsl:value-of select="$fileName" />

    > How can I call a value from the original document, at the specific
    > node from where the "document()" call took place?




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 26, 2004
    #1
    1. Advertising

  2. Hello!

    I have a problem while trying to refer from a file called by the
    document function to the document where it was called from. I give an
    example:

    <filelist>
    <file name="whatever">
    <url>foo/bar/somefile.xml</url>
    </file>
    <!-- ... -->
    </filelist>

    Now I call this template:

    <xsl:template match="filelist">
    <xsl:for-each select="file">
    <xsl:apply-templates select="document(url)//xyz"/>
    </xsl:for-each>
    </xsl:template>

    Now I want the "xyz" template to get the "name" value of "file". I
    tried the following (with Saxon 7.9.1), but apparently I can't reach
    out of the document that has been called with "document()".

    <xsl:template match="xyz"
    <!-- do some stuff -->
    <xsl:value-of select="ancestor::file/@name"/>
    </xsl:template>

    How can I call a value from the original document, at the specific
    node from where the "document()" call took place?

    Bye,
    Boris
    =?iso-8859-1?Q?Boris_P=F6hlmann?=, May 26, 2004
    #2
    1. Advertising

  3. "Martin Honnen" <> schrieb:
    >
    > Consider using
    > <xsl:call-template name="templateName">
    > <xsl:with-param name="fileName" select="@name" />
    > <xsl:with-param name="xyz" select="document(url)//xyz" />
    >

    Thank you. That's like what I've done for now, but I consider it a
    "workaround". In a more general case, there could be dozens of values
    to access, and then I wouldn't want to give them all as params. Anyway,
    it works for the moment. :)

    Thanks,
    Boris
    =?iso-8859-1?Q?Boris_P=F6hlmann?=, May 26, 2004
    #3
  4. In article <c92hqm$7tu$>, Boris Pöhlmann <> wrote:

    >> <xsl:with-param name="fileName" select="@name" />


    > Thank you. That's like what I've done for now, but I consider it a
    >"workaround". In a more general case, there could be dozens of values
    >to access, and then I wouldn't want to give them all as params.


    Just pass the current node itself as a parameter (select="."). Then
    you can access all its children, attributes, etc just as you would
    have done in the calling template.

    -- Richard
    Richard Tobin, May 26, 2004
    #4
  5. "Richard Tobin" <> schrieb:
    >
    > Just pass the current node itself as a parameter (select=".").
    >

    Works fine, thanks! :)

    Bye,
    Boris
    =?iso-8859-1?Q?Boris_P=F6hlmann?=, Jun 1, 2004
    #5
    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. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,963
    jan V
    Jul 29, 2005
  2. Vitali Gontsharuk
    Replies:
    2
    Views:
    1,664
    Vitali Gontsharuk
    Aug 21, 2005
  3. Matt DeFoor

    reading file backwards and parsing

    Matt DeFoor, Apr 12, 2004, in forum: C Programming
    Replies:
    11
    Views:
    4,040
    Barry Schwarz
    Apr 14, 2004
  4. cman

    Moving pointers backwards and forwards

    cman, Mar 2, 2007, in forum: C Programming
    Replies:
    4
    Views:
    266
  5. Orestis Markou
    Replies:
    1
    Views:
    312
    Martin v. Löwis
    Oct 8, 2008
Loading...

Share This Page