Search code examples
loopsxsltxslt-1.0child-nodes

How to loop through child nodes using XSLT1.0


I have below xml fragment. I need to loop through all the child nodes based on some condition and print the node name.

  <Parentnode>
        <Date>01-Jan-2017</Date>
        <Aab>w</Aab>
        <Abc>g</Abc>
        <Anb>16</Anb>
        <Amr>25</Amr>
  </Parentnode>

I need to output all the child node name which is not <Date> node and all the child node names whose value is not 'g'.

Something like this.

<Parentnode>
   <Code>Aab</Code>
   <Code>Anb</Code>
   <Code>Amr</Code>
</Parentnode>

Request you to help on this.

Thanks.


Solution

  • Try it this way:

    <xsl:template match="Parentnode">
        <xsl:copy>
            <xsl:for-each select="*[not(self::Date or .='g')]">
                <!-- do something -->
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>