This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: xpath - getting precedeing-sibling::element/@id ?


> The following stylesheet will output the preceding
> siblings (of which there 
> is one in your source code).


what about multiple siblings? If I have 5 siblings, i
only want the first preceding-sibling::

also, there is no gaurantee that the preceding element
is a sibling of the current node.

I'm thinking more along the lines of getting the
preceding::tab element (cousin (diff parent) or
sibling) where the current element has tab/@state='on'

for example:

<tab state="off">
  <tab id="1.2.1"></tab>
  <tab id="1.2.2"></tab>
  <tab id="1.2.3"></tab>
</tab>
<tab state="on">
  <tab id="1.3.1" state="on"></tab>
</tab>
<tab state="off">
  <tab id="1.4.1"></tab>
</tab>


if i'm on tab where id="1.3.1" & state="on", i want to
grab the preceding nested <tab> (id='1.2.3')...

the end result I'm after is basically so that with the
deepest <tab> that has state="on", i can grab the
preceding/following deepest <tab>...in this case
yielding preceding <tab id="1.2.3"> and following <tab
id="1.4.1">



--- AndrewWatt2000@aol.com wrote:
> In a message dated 10/07/01 20:21:55 GMT Daylight
> Time, apwebdesign@yahoo.com 
> writes:
> 
> 
> > using xpath, how do I find an element, with a
> specific
> > attribute (say <tab state="on">), and then grab
> it's
> > preceding and/or following element's (child or
> > sibling) 'id' attribute? (say <tab id="1.2.3">)
> > 
> > ...assuming this xml:
> > 
> > <tab state="on">
> > <tab id="1.2.3" state="off"></tab>
> > <tab id="1.2.4" state="on"></tab>
> > </tab>
> 
> Anthony,
> 
> The following stylesheet will output the preceding
> siblings (of which there 
> is one in your source code).
> 
> <?xml version='1.0'?>
> <xsl:stylesheet version="1.0"
>                
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 
> <xsl:template match="/">
> <html>
> <body>
> <xsl:apply-templates select="tab/tab[@state='on']"/>
> </body>
> </html>
> </xsl:template>
> 
> <xsl:template match="tab">
> <h3><xsl:value-of
> select="preceding-sibling::*"/></h3>
> </xsl:template>
> </xsl:stylesheet>
> 
> Andrew Watt
> 


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]