Re: [xsl] selecting the nearest preceding sibling

Subject: Re: [xsl] selecting the nearest preceding sibling
From: Nicolas Mazziotta <nicolas.mazziotta@xxxxxxxxx>
Date: Tue, 13 May 2003 15:47:12 +0200
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