Replacing text after node
- by Andrew
I am trying to remove the "Hide this data" from this XML which is proceeded with the qualifier type="noView"
<element version="Local">
<qualifier name="Public" type="View" />
Good to go
</element>
<element version="Local">
<qualifier name="Public" type="noView" />
Hide this data
</element>
I am using this XSL
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="qualifier">
<xsl:call-template name="replace-noview" />
</xsl:template>
<xsl:template name="replace-noview">
<xsl:param name="text" select="@type"/>
<xsl:choose>
<xsl:when test="contains($text, 'noView')">
<xsl:copy-of select="."/>
<xsl:text>DELETED</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The output I'm getting is
<element identifier="ContactName" version="Local">
<qualifier name="Public" type="View" />
Good to go
</element>
<element identifier="ContactName" version="Local">
<qualifier name="Public" type="noView" />DELETED
Hide this data
</element>
I am matching the "noView" attribute and can add the "DELETED" text. However I need to remove the follow "Hide this data" text.
The output I would like is
<element identifier="ContactName" version="Local">
<qualifier name="Public" type="View" />
Good to go
</element>
<element identifier="ContactName" version="Local">
<qualifier name="Public" type="noView" />
DELETED
</element>