Wednesday, April 10, 2013

XSL - Getting next node/previous node from the current node

XML Data

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <datum>
        <x>ABCDE</x>
        <y>30</y>
    </datum>
    <datum>
        <x>BCDEF</x>
        <y>20</y>
    </datum>
    <datum>
        <x>CDEFG</x>
        <y>-57</y>
    </datum>

</data>

XSL


<xsl:for-each select="data/datum">
      <xsl:value-of select="current()/preceding-sibling::*[1]/y"/>

      <xsl:value-of select="current()/y"/>
      <xsl:value-of select="current()/following-sibling::*[1]/y"/>
</xsl:for-each> 


Result

30 20 -57

3:08 PMtech-mashup