Vinay D
Vinay D

Reputation: 273

If condition in XSLT

I have an XML file which is getting embedded into the master xml file, below is the xml file format

<TEST_RESULT>
<MODULE_NAME>CREATE-SETVC-NUM</MODULE_NAME>
<CLASS_NAME>Create</CLASS_NAME>
<NUMBER_OF_PASSED>4</NUMBER_OF_PASSED>
<NUMBER_OF_FAILED>4</NUMBER_OF_FAILED>
<TOTAL_COUNT>8</TOTAL_COUNT>
<CLASS_NAME1>SetVC</CLASS_NAME1>
<NUMBER_OF_PASSED1>4</NUMBER_OF_PASSED1>
<NUMBER_OF_FAILED1>4</NUMBER_OF_FAILED1>
<TOTAL_COUNT1>8</TOTAL_COUNT1>
</TEST_RESULT>

Now my XSLT file i need to check an condition that when nodes <CLASS_NAME> and <CLASS_NAME1> both nodes exists need to perform some operation, now i tried this below condition

    <xsl:when test="CLASS_NAME and CLASS_NAME1">
    <tr>
    <td rowspan="2" bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="MODULE_NAME"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="CLASS_NAME"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="NUMBER_OF_PASSED"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="NUMBER_OF_FAILED"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="TOTAL_COUNT"/></b></font></td>

    </tr>

    <tr>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="CLASS_NAME1"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="NUMBER_OF_PASSED1"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="NUMBER_OF_FAILED1"/></b></font></td>
    <td bgcolor = "#E0FFFF"><font face = "courier"><b><xsl:value-of select="TOTAL_COUNT1"/></b></font></td>
    </tr>
    </xsl:when>

but this condition is failing any idea why its failing?

Upvotes: 2

Views: 2721

Answers (2)

Pavan
Pavan

Reputation: 1289

Condition check are of two types in XSLT 1.0

  1. xsl If condition to match a template,

    <xsl:if test="expr">

    <!-- your code -->

    </xsl:if>

  2. element is used in conjunction with and to express multiple conditional tests.

      `<xsl:choose>
         <xsl:when test="expr">
         <!-- your code -->
        </xsl:when>
    
       <xsl:otherwise>
         <!-- your code -->
       </xsl:otherwise>
    

    `

,

Reference:

[w3schools.com/xsl/] [zvon.org/comp/r/ref-XSLT_1.html]

to learn xslt zvon is very good site for newbies :)

Upvotes: 1

R. Oosterholt
R. Oosterholt

Reputation: 8080

needs to be either:

<xsl:choose>
    <xsl:when test="CLASS_NAME and CLASS_NAME1">
    </xsl:when>
</xsl:choose>

or:

<xsl:if test="CLASS_NAME and CLASS_NAME1">
</xsl:if>

Upvotes: 3

Related Questions