XPath

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ShakyMobo

    #1

    XPath

    <line><c n="H7">Drinki n' 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



  • Martin Honnen

    #2
    Re: XPath



    ShakyMobo wrote:
    [color=blue]
    > <line><c n="H7">Drinki n' 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.[/color]

    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/

    Comment

    • ShakyMobo

      #3
      Re: XPath

      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" <mahotrash@yaho o.de>
      Newsgroups: comp.text.xml
      Sent: Thursday, March 10, 2005 6:47 PM
      Subject: Re: XPath

      [color=blue]
      >
      >
      > ShakyMobo wrote:
      >[color=green]
      >> <line><c n="H7">Drinki n' 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.[/color]
      >
      > 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/[/color]


      Comment

      • Martin Honnen

        #4
        Re: XPath



        ShakyMobo wrote:

        [color=blue]
        > 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?[/color]

        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/

        Comment

        Working...