XPath

S

ShakyMobo

<line><c n="H7">Drinkin' all </c><c n="E">night</c><c n="E7">We got in to a
</c><c n="A">fight</c></line>

XPath: substring(/line/c[position()=1], 3, 7)

Is it possible to refer to the textelement that contains the value of the
substring in XSLT? In this case the firstchild of the first "c" element.
I'm doing this in Java, and my clumsy solution was to take out the string
"/line/c[position()=1]" and find the firstchild of the returned node.
I need to split up the textelement in order to insert a new element inside
the textelement, and that's why i need to point at the textelement.

Arnstein
 
M

Martin Honnen

ShakyMobo said:
<line><c n="H7">Drinkin' all </c><c n="E">night</c><c n="E7">We got in to a
</c><c n="A">fight</c></line>

XPath: substring(/line/c[position()=1], 3, 7)

Is it possible to refer to the textelement that contains the value of the
substring in XSLT? In this case the firstchild of the first "c" element.
I'm doing this in Java, and my clumsy solution was to take out the string
"/line/c[position()=1]" and find the firstchild of the returned node.
I need to split up the textelement in order to insert a new element inside
the textelement, and that's why i need to point at the textelement.

I am not sure I understand, in the DOM there are different kind of
nodes, there are element nodes and there are text nodes but I don't know
what you think a textelement is.
As for XPath, surely you can do
/line/c[1]/text()[1]
to select the first text child node of the first <c> element child node
of the <line> root element.
 
S

ShakyMobo

I was probably thinking of the textnode :)
But the thing is that I can't change the Xpath expression
"substring(/line/c[position()=1], 3, 7)"
Is it possible to use that expression to find the textnode that contains
resulting string?


----- Original Message -----
From: "Martin Honnen" <[email protected]>
Newsgroups: comp.text.xml
Sent: Thursday, March 10, 2005 6:47 PM
Subject: Re: XPath

<line><c n="H7">Drinkin' all </c><c n="E">night</c><c n="E7">We got in to
a </c><c n="A">fight</c></line>

XPath: substring(/line/c[position()=1], 3, 7)

Is it possible to refer to the textelement that contains the value of the
substring in XSLT? In this case the firstchild of the first "c" element.
I'm doing this in Java, and my clumsy solution was to take out the string
"/line/c[position()=1]" and find the firstchild of the returned node.
I need to split up the textelement in order to insert a new element
inside the textelement, and that's why i need to point at the
textelement.

I am not sure I understand, in the DOM there are different kind of nodes,
there are element nodes and there are text nodes but I don't know what you
think a textelement is.
As for XPath, surely you can do
/line/c[1]/text()[1]
to select the first text child node of the first <c> element child node of
the <line> root element.
 
M

Martin Honnen

ShakyMobo wrote:

But the thing is that I can't change the Xpath expression
"substring(/line/c[position()=1], 3, 7)"
Is it possible to use that expression to find the textnode that contains
resulting string?

I am not sure I understand what you want to achieve, you can write
predicates in XPath expression to filter out certain nodes e.g.
/line/c/text()[contains(., substring(/line/c[position()=1], 3, 7))]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top