Is '//' and 'descendant-or-self' not the same

Help
Stefan_E
2012-09-16
2012-10-08
  • Stefan_E
    Stefan_E
    2012-09-16

    Sorry for reviving such an old thread: Whilst I can see the logic in above
    example, I still get confused on my example... hmm (using Saxon 9.4.0.3
    through Oxygen)

    My document looks something like this (graphml file to be processed with yed):

    <root>
    <node isLeaf="Y"/>
    <node isLeaf="N">
    <graph>
    <node isLeaf="Y"/>
    <node/>
    </graph>
    </node>
    <node isLeaf="N">
    <graph/>
    </node>
    <node isLeaf="N">
    <graph>
    <node isLeaf="Y"/>
    </graph>
    </node>
    </root>

    I don't want remove the node which doesn't have a leaf node <node isLeave="Y">
    So, I'm using an xsl template as follows:

    <xsl:template match="node">
    <xsl:if test="descendant-or-self::node">
    <node>
    <xsl:apply-templates select="@*|node()"/>
    </node>
    </xsl:if>
    </xsl:template>

    which works.

    But using

    <xsl:if test="//node">

    copies everything ...How does the predicate get matched?

    Thanks for help,
    Stefan

     
  • Stefan_E
    Stefan_E
    2012-09-16

    "I don't want remove" --> I want remove ... :-)

     
  • Markus Abt
    Markus Abt
    2012-09-16

    No, "//" is not the same as "descendant-or-self".
    Neither is "descendant-or-self::node" the same as "//node".

    "//" is the same as "/descendant-or-self::node()/".

    Therefore, "//node" is the same as "/descendant-or-self::node()/child::node"
    Which is in two aspects different from "descendant-or-self::node":
    1. the former starts at the root node "/", the latter doesn't.
    2. Note the additional step on the child axis in the former.

    Regards,
    Markus