xsl-list
[Top] [All Lists]

RE: extract xpath locator

2004-08-11 05:30:36

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.



<Prev in Thread] Current Thread [Next in Thread>