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

RE: XPath to select based on attr = same attr of an a

Subject: RE: XPath to select based on attr = same attr of an ancestor
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 14 Jul 2008 08:25:45 +0100
RE:  XPath to select based on attr = same attr of an  a
I think it's:

match="foreign[@lang = (ancestor::*/@lang)[last()]]"

which is valid in both 1.0 and 2.0.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Syd Bauman [mailto:Syd_Bauman@xxxxxxxxx] 
> Sent: 14 July 2008 01:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XPath to select based on attr = same attr of 
> an ancestor
> 
> The idea here is that I want a template that will match any 
> <foreign> element that has a lang= attribute with a value 
> that matches the lang= attribute value of said <foreign> 
> element's nearest ancestor that has a lang= attribute 
> specified. (So that I can delete said
> <foreign>.) I.e. in
> 
>    <div lang="en">
>      <p>Only <foreign lang="en">one</foreign> more!</p>
>      <p>Only <foreign lang="es">uno</foreign> more!</p>
>    </div>
> 
> the first <foreign> should be matched, and the second should not.
> Thus the above should become
> 
>    <div lang="en">
>      <p>Only one more!</p>
>      <p>Only <foreign lang="es">uno</foreign> more!</p>
>    </div>
> 
> I used the following XPath on the match= of an <xsl:template>:
>  foreign[@lang][ancestor::*[@lang]][1][ ./@lang = 
> ./ancestor::*[@lang][1]/@lang ] While my stylesheet seems to 
> work for simple cases, it fails for many cases, too. (Like 
> missing all but the 1st <foreign> in a <p>.)
> 
> In case it helps, I have made the requisite files available 
> via the web (see below), but it may be the case that sharp 
> eyes here can pick up on some detail I've messed up just by 
> looking at the XPath itself.
> And while I'd prefer to stick with XSLT 1 and thus XPath 1, 
> XSLT 2 and thus XPath 2 is an option.
> 
>  1) the story:
>     http://bauman.zapto.org/~syd/temp/rrfq/story.txt
>  2) the XSLT 1.0 stylesheet itself
>     
> http://bauman.zapto.org/~syd/temp/rrfq/remove_redundant_foreig
n_elements.xslt
>  3) a test input XML file
>     
> http://bauman.zapto.org/~syd/temp/rrfq/test_remove_redundant_f
oreign_input.xml
>  4) the desired output
>     
> http://bauman.zapto.org/~syd/temp/rrfq/test_remove_redundant_f
oreign_desired.xml
>  5) the actual output
>     
> http://bauman.zapto.org/~syd/temp/rrfq/test_remove_redundant_f
oreign_output.xml

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-2011 All Rights Reserved.