This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
How to define the XPath expression to retrieve a following/preceding element in an XInclude
- To: <XSL-List at lists dot mulberrytech dot com>
- Subject: [xsl] How to define the XPath expression to retrieve a following/preceding element in an XInclude
- From: "Ed Steenhoek" <e dot steenhoek at chello dot nl>
- Date: Wed, 5 Sep 2001 22:23:51 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hello,
I'm having troubles defining the XPath expression to retrieve a
following/preceding element in an XInclude. In words I would like to do
this:
retrieve the value of the navID attribute
of a navKey
of a group
that follows/precedes the group
that has a navKey
where the navID has value (e.g.) S002
In details:
This is a simplified version of the XML file:
<Test>
<group>
<navKey navID="S001"/>
<content>Content for page 1</content>
</group>
<group>
<navKey navID="S002"/>
<content>Content for page 2</content>
</group>
<group>
<navKey navID="S003"/>
<content>Content for page 3</content>
</group>
<group>
<navKey navID="S004"/>
<content>Content for page 4</content>
</group>
</Test>
To retrieve the navKey of the next group in an XSL stylesheet (thus no
include!) I use:
<xsl:value-of select="following::group[1]/navKey/@navID"/>
The result will be S003 when the current node is <navKey navID="S002"/>
To retrieve the navKey of the previous group in an XSL stylesheet I use:
<xsl:value-of select="preceding::group[1]/navKey/@navID"/>
The result will be S001 when the current node is <navKey navID="S002"/>
So far so good. But know want to create an XML Include to retrieve the same
identifiers using a parameter to specify the 'current' ID (in more detail it
is the ID of the requested content which will be included by an generic page
from an external XML file).
The include starts at the root of the XML file and not at an arbitrary
navKey somewhere in the tree. To execute the include I'm using cocoon but I
define the XInclude namespace not at the XSP page level and thus the include
will not be executed in an XSP processing step. My assumption is that, the
fact that I'm using Cocoon, is (should be?) irrelevant to my problem since
the XInclude could also be processed outside cocoon.
The syntax I use is:
<include xinclude:parse="xml" xinclude:href="somefile.xml#xpointer(...XPath
expression...)"/>
To retrieve all four navKey elements, I use:
<include xinclude:parse="xml"
xinclude:href="somefile.xml#xpointer(//navKey)"/>
To retrieve one particular navKey element, I use:
<include xinclude:parse="xml"
xinclude:href="somefile.xml#xpointer(//navKey[@navID='S001'])"/>
But what is the XPath expression the retrieve the preceding or following
navKey element?
I tried: //navKey[@navID='S001'][following::group[1]/navKey/@navID] but that
does not do the trick. Anyone an idea?
Regards,
Ed Steenhoek
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list