0

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>
  • 1
    You want to have a look at [](http://stackoverflow.com/questions/585261/is-there-an-xslt-name-of-element#answer-585290). – webketje Mar 21 '17 at 12:19
  • Oh my God. I spent all day yesterday trying different things and it is so so so simple!. Thanks Tyblitz. You have ended my stress. Wow. You are my Miracle Worker –  Mar 21 '17 at 12:23

1 Answers1

1
<?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>