473,487 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XPath and document() function - backwards

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

Jul 20 '05 #1
4 3547


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/

Jul 20 '05 #2
"Martin Honnen" <ma*******@yahoo.de> 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

Jul 20 '05 #3
In article <c9**********@online.de>, Boris Pöhlmann <B.***@gmx.de> 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
Jul 20 '05 #4
"Richard Tobin" <ri*****@cogsci.ed.ac.uk> schrieb:

Just pass the current node itself as a parameter (select=".").

Works fine, thanks! :-)

Bye,
Boris
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6044
by: Neil Zanella | last post by:
Hello, I would like to know whether the mozilla web browser has built in support for searching XML documents via XPath expressions as with IE's xmlobject's and xmlDoc's function selectNodes() or...
2
2952
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
1
2032
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the...
1
4254
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
4
6047
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the...
3
3237
by: ziggyware | last post by:
Hi All, I have updated my XPath Generator software: XPath Studio .NET. ( http://www.ziggyware.com/downloads.php?cat_id=2 ) Easily select nodes from an xml file to generate XPath statements ...
1
5686
by: PAF | last post by:
Hi, I'm trying to evaluate a sum expression trougth .NET 2 System.Xml.XPath.XPathNavigator object. My code is : Dim document As New System.Xml.XmlDocument() document.LoadXml("<?xml...
6
1996
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.