Xelian
Xelian

Reputation: 17228

Does the CDATA slows the xslt transformation in XSLT 1.0

I use XPATH 1.0 and XSLT 1.0. I am wondering if the following code

<xsl:choose>
    <xsl:when test="@name='some'"><![CDATA[one]]></xsl:when>
    <xsl:otherwise><![CDATA[two]]></xsl:otherwise>
</xsl:choose>

has a difference in case of performance with

 <xsl:choose>
        <xsl:when test="@name='some'"><xsl:value-of select="'one'"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="'two'"/></xsl:otherwise>
    </xsl:choose>

if we know that there must be no need for some special symbols in the select? Is it a good practice to use <![CDATA[one]]>. Or its use decrease the xslt compilation time, or it is easy to read??

Upvotes: 0

Views: 97

Answers (1)

Aris2World
Aris2World

Reputation: 1234

In my opinion if there's a performance improvement it is not so significant to justify your first example.

In this case I would pay more attention about maintenance and readability as your second example. With this solution if you want change how elements have to be rendered (as cdata or not) you can use the attribute cdata-section-elements in the output element.

Here's a good example about it How to use cdata in xslt

Upvotes: 0

Related Questions