Skip to content Skip to sidebar Skip to footer

Retain HTML Tags After Xslt

i have following xslt parsing tree.

Solution 1:

Since you need to retain some tags as is in the output, you can start with an identity transform template which copies the input as is to the output.

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
</xsl:template>

In the template matching body use <xsl:apply-templates> instead of <xsl:copy-of>.

<xsl:template match="body">
    <div id="storybodycontent">
        <span class="storycontent">
            <xsl:apply-templates />
        </span>
    </div>
</xsl:template>

The complete XSLT will look like

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" />
    <xsl:strip-space elements="*" />

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="body">
        <div id="storybodycontent">
            <span class="storycontent">
                <xsl:apply-templates />
            </span>
        </div>
    </xsl:template>

    <xsl:template match="div[@class='tr-summaryinfo']">
        <ul>
            <xsl:apply-templates />
        </ul>
    </xsl:template>

    <xsl:template match="p[@class='tr-summaryitem']">
        <li>
            <xsl:apply-templates />
        </li>
    </xsl:template>
</xsl:stylesheet>

This should give the required output.


Post a Comment for "Retain HTML Tags After Xslt"