I am trying to exclude a specific set of html tags from an xml string using XSLT 1.0
Here, at present, I exclude the <a> and <img> tags. For the <a> tag, I want to display only text.
Designed XSLT Template:
<xsl:template match="*" mode="ExcludeHTMLTags"> <xsl:choose> <xsl:when test="local-name() = 'a' or local-name() = 'img'"> <xsl:value-of select="text()"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="node()|@*"/> </xsl:otherwise> </xsl:choose> </xsl:template>
Call the template below:
<xsl:variable name="guideContent"> <root> <xsl:apply-templates select="document(@guideID)/tcm:Component/tcm:Data/tcm:Content/em:GeneralContent/em:Body/node()" mode="expandXHTML"/> </root> </xsl:variable> <xsl:apply-templates select="msxsl:node-set($guideContent)/node()" mode="ExcludeHTMLTags"/>
XML input string:
<root> This is a test message. <p>Message within p tag</p> click <a href="www.test.com">here</a>. <img src="/test.jpg" /> Message after image. <strong>Message within strong</strong> <link:component id="XXX" ... >My Link</link:component> <p>Message after link component</p> </root>
OUTPUT:
<root> This is a test message. <p>Message within p tag</p> click here. Message after image. <strong>Message within strong</strong> <link:component id="XXX" ... >My Link</link:component> <p>Message after link component</p> </root>
Please suggest what I am doing wrong and will tell you in the best way.
source share