What does a "//" mean in an xpath expressin?

Discussion in 'XML' started by eric.goforth@gmail.com, Aug 18, 2006.

  1. Guest

    In an xsl stylesheet, I have

    <xsl:when test="string-length(//mystuff) &gt; 0">
    <xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
    </xsl:when>

    In the xml that mystuff is several layers deep, does the // do a search
    in the xpath?

    <test>
    <another_level>
    <mystuff>testing123</mystuff>
    </another_level>
    </test>
     
    , Aug 18, 2006
    #1
    1. Advertising

  2. Guest

    wrote:
    > In an xsl stylesheet, I have
    >
    > <xsl:when test="string-length(//mystuff) &gt; 0">
    > <xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
    > </xsl:when>
    >
    > In the xml that mystuff is several layers deep, does the // do a search
    > in the xpath?
    >
    > <test>
    > <another_level>
    > <mystuff>testing123</mystuff>
    > </another_level>
    > </test>


    Answering my own question, from the w3schools website:

    Selecting Nodes

    XPath uses path expressions to select nodes in an XML document. The
    node is selected by following a path or steps. The most useful path
    expressions are listed below:
    Expression Description
    nodename Selects all child nodes of the node
    / Selects from the root node
    // Selects nodes in the document from the current node that match the
    selection no matter where they are
    .. Selects the current node
    ... Selects the parent of the current node
    @ Selects attributes

    I'd tried searching w3schools, Google Group, etc. But couldn't find
    anything for the "//" string.

    -Eric
     
    , Aug 18, 2006
    #2
    1. Advertising

  3. Joseph Kesselman, Aug 18, 2006
    #3
  4. schrieb:
    > <xsl:when test="string-length(//mystuff) &gt; 0">
    > <xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
    > </xsl:when>
    >
    > In the xml that mystuff is several layers deep, does the // do a search
    > in the xpath?


    See the XPath 1.0 spec (<http://www.w3.org/TR/xpath#path-abbrev>):
    //para selects all the para descendants of the document root and thus
    selects all para elements in the same document as the context node
    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
     
    Johannes Koch, Aug 18, 2006
    #4
  5. The exact definition from the W3C spec:

    "// is short for /descendant-or-self::node()/"

    This means a number of things, one is that, obviously, "//" only by itself
    is not a valid XPath expression.

    The other, that is a very frequent mistake people make is that

    //something[1]

    is not the same as

    (//something)[1]

    and it's possible that

    count(//something[1])

    may be greater than one

    Cheers,
    Dimitre Novatchev

    <> wrote in message
    news:...
    > In an xsl stylesheet, I have
    >
    > <xsl:when test="string-length(//mystuff) &gt; 0">
    > <xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
    > </xsl:when>
    >
    > In the xml that mystuff is several layers deep, does the // do a search
    > in the xpath?
    >
    > <test>
    > <another_level>
    > <mystuff>testing123</mystuff>
    > </another_level>
    > </test>
    >
     
    Dimitre Novatchev, Aug 19, 2006
    #5
    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,993
    jan V
    Jul 29, 2005
  2. Anna
    Replies:
    0
    Views:
    541
  3. Li Ma
    Replies:
    1
    Views:
    2,312
    Roedy Green
    Mar 9, 2009
  4. Rahul
    Replies:
    4
    Views:
    600
    Robert Kern
    Apr 7, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,232
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page