Xsl - last previous brother

I'm stuck with the logic related to the previous brother,

Trying to keep plain XML.

<order>
<orderList>
<itemid><id>100</id></itemid>
<itemid><id>100</id></itemid>
<itemid><id>111</id></itemid>
<itemid><id>111</id></itemid>
<itemid><id>123</id></itemid>
<itemid><id>324</id></itemid>
<itemid><id>244</id></itemid>
<itemid><id>244</id></itemid>
 </orderList>
</order>

I am trying to find the previous brother for each node using below xsl. I need to use for each loop to match this logic in larger xsl ...

  <html>
  <body>
     <table border="1">
   <xsl:for-each select="order/orderList/itemid">
      <tr>
        <td>itemid</td>
        <td><xsl:value-of select="id" /> </td>
        <td> <xsl:value-of select="preceding-sibling::node()"/>   </td>
      </tr>
      </xsl:for-each>
    </table>    
  </body>
  </html>
</xsl:template>

I get these Results 

itemid 100  
itemid 100 100   
itemid 111 100 
itemid 111 100   - expecting 111
itemid 123 100   - expecting 111 etc
itemid 324 100 
itemid 244 100 
itemid 244 100 

any help please?

+5
source share
1 answer

In XSLT 1.0, xsl: value-when specifying node-set, returns the string value of the first node in this node -set, taken in document order. (XSLT 2.0 returns the string values โ€‹โ€‹of all nodes in node-set).

previous-sibling :: node () returns a node set containing all previous node siblings.

If you need only the last previous brother, use before-sibling :: * [1].

+6
source

All Articles