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

RE: extract xpath locator

Subject: RE: extract xpath locator
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 11 Aug 2004 13:30:36 +0100
xpath kay
> I would like to write template that returns the exact xpath 
> expression that locates a tag in mixed-content documents.
> 
> eg, i have:
> 
> <doc>
> 	This <i>is</i> a <b>T</b>est
> </doc>
> 
> and I would like to get 
> 
> the Xpath that says that "i" includes char 6 and 7, and	
> "b"  char 11 of "/doc"
> 

I'm not sure how you are counting, you seem to be counting the space after
"This" but not the spaces before?

Ignoring that problem, though, the start position for the <i> element is the
sum of the string-lengths of the preceding text nodes. In XPath 2.0 that's

sum(for $n in preceding::text() return string-length($n))

and the end position is the same, plus the string-length of the element
itself.

Summing over a computed value is more tricky in XSLT 1.0: you can do it
using FXSL, or by recursion, or by creating a temporary tree.

Michael Kay

PS: Every time I post to xsl-list, I'm getting a message from some site in
China that says my content is prohibited. Well, it might be prohibited in
China, but that's not my problem, and I don't really want to know.

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.