Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-1145

ancestor and ancestor-or-self axis sometimes return wrong element

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 2.4Dx
    • None
    • XPath
    • None
    • Operating System: Windows NT/2K
      Platform: PC
    • 11941

    Description

      This might be related to bug 7886.

      When "count(ancestor::) > 1", "ancestor::[last()]" should be different than
      "ancestor::*[1]", right? Well, it doesn't seem so.

      To have it right, it seems we have to write an xpath of "./ancestor::*[last()]".
      Same issue with ancestor-or-self.

      My actual (working) code is:
      <xsl:template match"someelement">
      <xsl:message>
      count ancestors: <xsl:value-of select="count(ancestor::*)"/>
      last ancestor: <xsl:value-of select="local-name(./ancestor::*[last()])"/>
      1st ancestor: <xsl:value-of select="local-name(./ancestor::*[1])"/>
      </xsl:message>
      <xsl:template>

      Without the ./, last and 1st ancestors are the same element. I have other code
      like "id(@foo)/ancestor-or-self::*[last() - 2]", which is working fine, so I'd
      say / is our friend here.

      Or did I miss anything in XPath?

      Attachments

        Activity

          People

            Unassigned Unassigned
            benoit@synclude.com Benoit Maisonny
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: