select="following-sibling::notification[count(preceding-sibling::employeeName[1] | current()) = 1]" : following sibling « XSLT stylesheet « XML






select="following-sibling::notification[count(preceding-sibling::employeeName[1] | current()) = 1]"


File: Data.xml

<?xml version="1.0"?>
<group>
  <employeeName>Samson</employeeName>
  <notification>0001</notification>
  <notification>name 1</notification>
  <notification>0003</notification>

  <employeeName>Delihla</employeeName>
  <notification>0004</notification>
  <notification>0005</notification>
  <notification>0006</notification>
</group>

File: Transform.xslt
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="html" indent="yes" />
  <xsl:template match="/">
    <xsl:apply-templates select="group" />
  </xsl:template>
  <xsl:template match="group">
    <xsl:for-each select="employeeName">
      <tr>
        <td>
          <xsl:value-of select="." />
        </td>
        <xsl:for-each
          select="following-sibling::notification[count(preceding-sibling::employeeName[1] | current()) = 1]">
          <td>
            <xsl:value-of select="." />
          </td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Output:

<tr>
   <td>Samson</td>
   <td>0001</td>
   <td>name 1</td>
   <td>0003</td>
</tr>
<tr>
   <td>Delihla</td>
   <td>0004</td>
   <td>0005</td>
   <td>0006</td>
</tr>

 








Related examples in the same category

1.following-sibling demo
2.following-sibling
3.select="following-sibling::*[1]/contact/name/firstName"
4.following-sibling::node()[1][not(self::NL)]