Replacing text after node

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-03-24T21:13:44Z Indexed on 2010/03/24 21:43 UTC
Read the original article Hit count: 213

Filed under:
|

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>

© Stack Overflow or respective owner

Related posts about xslt

Related posts about find-and-replace