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

Re: selecting the nearest preceding sibling

Subject: Re: selecting the nearest preceding sibling
From: Nicolas Mazziotta <nicolas.mazziotta@xxxxxxxxx>
Date: Tue, 13 May 2003 15:47:12 +0200
xpath preceding tags
Mukul wrote:
Hello ,
My XML file is below

XML file
------------
<rootelem>

<tag> --- node 1
<a>1</a>
<b>2</b>
<c>3</c>
<d>4</d>
</tag>

<tag>  --- node 2
<b>5</b>
<c>6</c>
<d>7</d>
</tag>

<tag>  --- node 3
<a>8</a>
<b>9</b>
<c>10</c>
<d>11</d>
</tag>

<tag>   --- node 4
<b>12</b>
<c>13</c>
<d>14</d>
</tag>

<tag>	--- node 5
<b>15</b>
<c>16</c>
<d>17</d>
</tag>

</rootelem>
----------------------
I want to write **a XPATH expression which will select
the nearest preceding sibling , which contains a
particular element ( <a> in this example) ** . I do
not want preceding sibling which do not contain the
<a> tag (also the tag <a> should be nearest to the
context node)

for e.g. if the context node is node 5 , the XPATH
expression which will select node 3(because it
contains element <a>) or for e.g. if the context node
is node 2 , the XPATH expression will select node
1(because it contains element <a>)

I am trying with preceding-sibling::tag ??

Can somebody suggest a solution?

Regards,
Mukul




__________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



maybe this?
was that what you meant?

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="tag">
&#xD;<xsl:apply-templates></xsl:apply-templates><xsl:value-of select="preceding::tag[descendant::a][position()=1]"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>


output is

	
1234

	
567 1 2 3 4

	
891011 1 2 3 4

	
121314 8 9 10 11

	
151617 8 9 10 11

--
+----------------------------+
|Nicolas Mazziotta           |
|Aspirant au doctorat        |
|Linguistique française      |
|Département d'études romanes|
|Université de Liège         |
+----------------------------+
|04/3665382                  |
|nicolas.mazziotta@xxxxxxxxx |
+----------------------------+


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.