Thursday, February 28, 2013

Checking for Match values in XSLT

XSLT Sheet:
----------------------------------------------------

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
    <xsl:variable name="value">
        <xsl:choose>
            <xsl:when test="/root[not(n1 != 'PROCESSED')]">
                <xsl:value-of select="'PROCESSED'"/>
            </xsl:when>
            <xsl:when test="/root[not(n1[. != 'FAILED' and . != 'ERROR'])]">
                <xsl:value-of select="'ERROR'"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="'NEW'"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:text>$value = </xsl:text>
    <xsl:value-of select="$value"/>
</xsl:template>
</xsl:stylesheet>

Input:

<root>
    <n1>PROCESSED</n1>
    <n1>PROCESSED</n1>
    <n1>PROCESSED</n1>
</root>
Output:
$value = PROCESSED

Input:
<root>
    <n1>FAILED</n1>
    <n1>ERROR</n1>
    <n1>FAILED</n1>
</root>
or
<root>
    <n1>FAILED</n1>
    <n1>FAILED</n1>
    <n1>FAILED</n1>
</root>
Output:
$value = ERROR

Input:
<root>
    <n1>FAILED</n1>
    <n1>ERROR</n1>
    <n1>PROCESSED</n1>
</root>
Output:
$value = NEW

No comments:

Post a Comment

Provide your thoughts !