[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Xpath for a range of elements

Subject: Xpath for a range of elements
From: "Anderson, Paul" <Paul.Anderson@xxxxxxxxxxxxx>
Date: Wed, 7 Feb 2007 17:53:17 -0500
 Xpath for a range of elements
Greetings,

Consider the following skeleton for an XML source file:

<section>
   <title>...</title>
   <para>...</para>
   <code-block>...</code-block>
   <para>...</para>
   <procedure>...</procedure>
   <para>...</para>
   <screen>...</screen>
   <para>...</para>
</section>

I need a Xpath expression that will return all nodes after the <title>
and before the <procedure> (i.e., from section/para[1] through
section/para[2]). Then I operate on the <procedure>. Then I need another
Xpath expression that returns all the nodes after the procedure up to
the end of the <section> (i.e., from section/para[3] through
section/para[4]. The source documents vary enough that I do not know in
advance the number of elements or nature of the elements before or after
the <procedure>. I do, however, know that there is always one (and only
one) <procedure>.

In my research, I came across the following thread on this list
(http://www.biglist.com/lists/xsl-list/archives/200608/msg00043.html).
This thread appeared to hold the answer for me but I can't make it work.
I saw that the solution was specific to Xpath 2.0 so I made sure to
upgrade to Saxon 8 and to update my scripts so that they would work
(e.g., migrate <xsl:document> to <xsl:result-document>, etc.).

Here is an approximation of the template that matches the section in the
example above:

<xsl:template match="section">
	<my-proc id="{@id}">
		<xsl:element name="proc-title">
			<xsl:value-of select="./title"/>
		</xsl:element>
		<xsl:element name="procbody">
			<xsl:element name="prereq">
				<xsl:apply-templates select="*[.
&lt;&lt; procedure[1]]"/>
			</xsl:element>
			<xsl:apply-templates select="./procedure"/>
			<xsl:element name="postreq">
				<xsl:apply-templates select="*[.
&gt;&gt; procedure[1]]"/>
			</xsl:element>
		</xsl:element>
	</my-proc>
</xsl:template>

I must be making a simple mistake. Any assistance is appreciated.

Best regards,

Paul Anderson



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.