Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath and document() function - backwards

Reply
Thread Tools

XPath and document() function - backwards

 
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2004


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">
<xslaram name="fileName" />
<xslaram 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/

 
Reply With Quote
 
 
 
 
=?iso-8859-1?Q?Boris_P=F6hlmann?=
Guest
Posts: n/a
 
      05-26-2004
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

 
Reply With Quote
 
 
 
 
=?iso-8859-1?Q?Boris_P=F6hlmann?=
Guest
Posts: n/a
 
      05-26-2004
"Martin Honnen" <(E-Mail Removed)> 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

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      05-26-2004
In article <c92hqm$7tu$(E-Mail Removed)>, Boris Pöhlmann <(E-Mail Removed)> 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
 
Reply With Quote
 
=?iso-8859-1?Q?Boris_P=F6hlmann?=
Guest
Posts: n/a
 
      06-01-2004
"Richard Tobin" <(E-Mail Removed)> schrieb:
>
> Just pass the current node itself as a parameter (select=".").
>

Works fine, thanks!

Bye,
Boris
 
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
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments