Jkrish
Jkrish

Reputation: 169

xsl:when test with CDATA not working

Xml is:

   <field name="Type">
        <![CDATA[Amount]]>
    </field>

Xpath in Xsl is

<xsl:when test="node()[@name='Type'] ='Amount'">

I am trying to check the value of Type. But it is not working. Please help.

Upvotes: 0

Views: 568

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

Give the XML markup

   <field name="Type">
        <![CDATA[Amount]]>
    </field>

the string contents of the field element is not only the word Amount but the word Amount preceded and followed by white space. So you need to use normalize-space

normalize-space(field[@name = 'Type']) = 'Amount'

or you need to use a contains check

contains(field[@name = 'Type'], 'Amount')

Upvotes: 2

Related Questions