user2414039
user2414039

Reputation:

Is it possible to replace value true with value deleted in xslt?

I have the following student xml doc. Is it possible to replace the value true with value DELETED in the output?

xml doc code

<Student>
    <Deleted>true</Deleted>
</Student>

xslt code

<Student>
    <xsl:choose>
        <xsl:when test="Deleted='true'">
            <xsl:value-of select="Deleted"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="PRESENT"/>
                </xsl:otherwise>
    </xsl:choose>
</Student>

I would like output to be

<Student>
    <StudentDeleted>DELETED</StudentDeleted>
</Student>

The following is what I am getting as output which is not what I want

<Student>
    <StudentDeleted>true</StudentDeleted>
</Student>

Upvotes: 0

Views: 38

Answers (1)

Gurusen Yadav
Gurusen Yadav

Reputation: 67

<?xml version="1.0" encoding="UTF-8"?>

<xsl:template match="Student">        
            <Student>
                <xsl:choose>
                    <xsl:when test="child::Deleted/text()='true'">
                        <StudentDeleted>
                        <xsl:value-of select="'Deleted'"/>
                        </StudentDeleted>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="PRESENT"/>
                    </xsl:otherwise>
                </xsl:choose>
            </Student>        
</xsl:template>

Upvotes: 1

Related Questions