Find Xpath Expn of current node using ancestor-or-self

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muthu08
    New Member
    • Sep 2007
    • 9

    Find Xpath Expn of current node using ancestor-or-self

    I'm trying to Xpath EXprn for a current node(name unknown).I tried using the below syntax,but it fails .Pls help.



    <xsl:variable name= "xpath" select ="name(ances tor-or-self::(.))"/>
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    probably
    <xsl:variable name="xpath" select="name()"/>
    or
    <xsl:variable name="xpath" select="local-name()"/>

    Comment

    • Muthu08
      New Member
      • Sep 2007
      • 9

      #3
      nmae() or local-name() would only return me th ename of the current node.But i'm trying to find out the Xpath Expression ,which would return the ancestors names also

      I need the name of current node plus its ancestors.

      ex: root/toplevelnode1/node2/ current node

      So i tried :

      <xsl:variable name= "xpath" select ="name(ances tor-or-self::[name()])"/>

      I need the syntax which would return current nodes path from the root.Pls help.

      thanks in advance.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        [code=xml]<xsl:variable name= "xpath">
        <xsl:for-each select="ancesto r::*">
        <xsl:value-of select="name()"/><xsl:text>/</xsl:text>
        </xsl:for-each>
        <xsl:value-of select="name()"/>
        </xsl:variable>[/code]

        Comment

        • Muthu08
          New Member
          • Sep 2007
          • 9

          #5
          Cool!! That worked Thanks!!

          Comment

          Working...