[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: extract xpath locator
> 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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|