You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Stefan Pietschmann <St...@inf.tu-dresden.de> on 2003/06/04 21:55:58 UTC

java - xml - xpointer problem

hi guys,

i already asked a similar question in the cocoon-users mailing list, so please excuse this, but since i got no answers and it wasn't really a cocoon specific question i'm gonna place it here once more...changed a bit.

I'm writing a Transformer for Cocoon... as input i have the DOM representation of a document. Let's say a part of this document is

....
<img ..../>
<span id="sometext">
    I went Home
</span>
...

Stored in a variable i have the id of a node, in this case "sometext". Furthermore I have a variable called pointer, which looks like "string-range(.,"Home")[1] ..something like this. It should be a proper XPointer expression, I can change that to whatever I want though.
Now the goal of the Transformer is to write an anchor around the string pointed to - "Home" in this case - which occurs in the node defined. I can make the span the context node and Java allows me to insert nodes before and after this one.. but how can i write an anchor around the specified string within this node?
Of course I could get the string, iterate through it and search for the word etc, but that would be a pain, esp. since there could be 18 instances and I would want the 17th etc.
Actually I'd like to use XPointer, so that some function returns the specified string-range in the node, and I can surround it with an <a> tag... that's what I thought ;)
So, is there an XPointer implementation that allows me that .. or how would you solve that problem?

Thanx,
Stefan Pietschmann