[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Text() Template copy conditionally


Subject: [xsl] Text() Template copy conditionally
From: Senthilukvelaan <skumaravelan@xxxxxxxxxxxxxx>
Date: Fri, 1 Jul 2011 12:47:58 -0700

Hi All,

In my identity template, where I need to replace "#" for downstream
processing, but I want to keep rest of the html entities which
might have "#" in them uninterrupted. Please help me , how do I
resolve this riddle?
This is my xslt for the same.


Thanks in advance for your input.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"  encoding="UTF-8" />

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


	<xsl:template match="text()">
	    <xsl:choose>
            <xsl:when test="text()[contains(.,'&amp;#')]">
	                   <xsl:copy>
       <xsl:apply-templates select="."/>
     </xsl:copy>            </xsl:when>
			<xsl:when test="text()[contains(.,'#')]">
    <xsl:variable name="hash">#</xsl:variable>
    <xsl:variable name="cleaned">
        <xsl:call-template name="_replace_string">
            <xsl:with-param name="string" select="." />
            <xsl:with-param name="find" select="$hash" />
                        <xsl:with-param name="replace" select="'&amp;#x23;'" />
        </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$cleaned" />
            </xsl:when>
            <xsl:otherwise>
               <xsl:copy>
       <xsl:apply-templates select="."/>
     </xsl:copy>
     </xsl:otherwise>
        </xsl:choose>
</xsl:template>
</xsl:stylesheet>


Thanks
Senthil


Current Thread
Keywords