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:templatematch="@* | node()"><xsl:copy><xsl:apply-templatesselect="@* | node()" /></xsl:copy></xsl:template>

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

<xsl:templatematch="body"><divid="storybodycontent"><spanclass="storycontent"><xsl:apply-templates /></span></div></xsl:template>

The complete XSLT will look like

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:outputmethod="xml" /><xsl:strip-spaceelements="*" /><xsl:templatematch="@* | node()"><xsl:copy><xsl:apply-templatesselect="@* | node()" /></xsl:copy></xsl:template><xsl:templatematch="body"><divid="storybodycontent"><spanclass="storycontent"><xsl:apply-templates /></span></div></xsl:template><xsl:templatematch="div[@class='tr-summaryinfo']"><ul><xsl:apply-templates /></ul></xsl:template><xsl:templatematch="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"