XPath and document() function - backwards

M

Martin Honnen

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: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
 
?

=?iso-8859-1?Q?Boris_P=F6hlmann?=

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?=

Martin Honnen said:
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
 
R

Richard Tobin

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top