Subject: [xsl] Xpath for a range of elements From: "Anderson, Paul" <Paul.Anderson@xxxxxxxxxxxxx> Date: Wed, 7 Feb 2007 17:53:17 -0500 |
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="*[. << procedure[1]]"/> </xsl:element> <xsl:apply-templates select="./procedure"/> <xsl:element name="postreq"> <xsl:apply-templates select="*[. >> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Generating point-numbered, Joe Fawcett | Thread | RE: [xsl] Xpath for a range of elem, Michael Kay |
RE: [xsl] Generating point-numbered, Michael Kay | Date | RE: [xsl] Xpath for a range of elem, Michael Kay |
Month |