XPath

Discussion in 'XML' started by ShakyMobo, Mar 10, 2005.

  1. ShakyMobo

    ShakyMobo Guest

    <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
     
    ShakyMobo, Mar 10, 2005
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Mar 10, 2005
    #2
    1. Advertising

  3. ShakyMobo

    ShakyMobo Guest

    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" <>
    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/
     
    ShakyMobo, Mar 10, 2005
    #3
  4. 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/
     
    Martin Honnen, Mar 11, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,976
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,417
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    529
  4. goog
    Replies:
    0
    Views:
    511
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,642
    Richard Tobin
    Nov 13, 2004
Loading...

Share This Page