Trouble with XPath for "preceding sibling"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apurvaG
    New Member
    • Apr 2007
    • 14

    Trouble with XPath for "preceding sibling"

    Hi All,

    I am facing a problem while fetching a preceding sibling with some specific name from current node.

    Following is the sample XML which I am using

    <Root>
    <document>
    <tid>100</tid>
    <location>SB</location>
    <category>C1</category>
    </document>
    <document>
    <tid>101</tid>
    <location>SB</location>
    <category>C3</category>
    </document>
    <document>
    <tid>102</tid>
    <location>JK</location>
    <category>C4</category>
    </document>
    </Root>

    Now suppose I am on 3rd <document> node [that is "tid = 102" ] and I want to check the values for the previous document's <location> node. If its is different than the current document's <location> then I need to call some other template.

    Can anyone please help. This is very urgent!


    Thanks in advance
    Apurva G.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    [code=xml]
    <xsl:if test="location != preceding-sibling::tid[1]/location">
    <xsl:call-template name="blah">
    ..
    [/code]

    Comment

    • apurvaG
      New Member
      • Apr 2007
      • 14

      #3
      Originally posted by jkmyoung
      [code=xml]
      <xsl:if test="location != preceding-sibling::tid[1]/location">
      <xsl:call-template name="blah">
      ..
      [/code]


      Will "preceding-sibling::tid[1]/location" refer to 2nd <document> node's locaton ? Another thing is location node is not child of <tid>. It is child of <document> node.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        sorry, must have been a brain fart:
        [code=xml]
        <xsl:if test="location != preceding-sibling::docume nt[1]/location">
        <xsl:call-template name="blah">
        ..
        [/code]

        Comment

        Working...