Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath

Reply
Thread Tools

XPath

 
 
ShakyMobo
Guest
Posts: n/a
 
      03-10-2005
<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



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-10-2005


ShakyMobo wrote:

> <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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
ShakyMobo
Guest
Posts: n/a
 
      03-10-2005
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" <(E-Mail Removed)>
Newsgroups: comp.text.xml
Sent: Thursday, March 10, 2005 6:47 PM
Subject: Re: XPath


>
>
> ShakyMobo wrote:
>
>> <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.
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      03-11-2005


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))]

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments