Hi All

I am new to XSLT development and have stuck at simple but essential point.
I want to remove the content which is in between two specific comment tag

<!--E-->Text which need to remove<!--/E-->

I do try with the given below code

<xsl:template match="comment()">
<xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:value-of select="."><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
</xsl:template>

<xsl:template match="E"/>

But it won't seem to work.

Try the below using XSLT 2.0:

<xsl:template match="text()">
<xsl:if test="preceding::comment() and following::comment()">
To test
</xsl:if>
</xsl:template>

<xsl:template match="comment()">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="comment()">
        <xsl:if test="contains(.,'Text which need to remove')"><xsl:comment>asdf</xsl:comment> </xsl:if>
    </xsl:template>

Hi JohnBampton and mrame

Thanks for quick reply and sorry for late response but your suggested code won't seem to work.
OK let me open my floor and let you know the real requirement
INPUT xml fragment

<atlgrp><atl><!--E-->Text to remove<!--/E-->Inhibition of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation<!--E-->Another text to remove<!--/E--></atl><runtl>Inhibition <!--E-->one another text to remove<!--/E-->of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation</runtl></atlgrp>

OUTPUT Should be

<atlgrp><atl>Inhibition of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation</atl><runtl>Inhibition of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation</runtl></atlgrp>

As john as you could see, I cannot fix specific text in contains() function and mrame your code always find prceding and following instance and every text it gets remove.
Hope now all will be clear with my requirement and I am looking forward with your answer.

Thanks

Make sure you have declared your entities.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
    <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates></xsl:apply-templates></xsl:copy></xsl:template>
    <xsl:template match="comment()">   
    </xsl:template>
</xsl:stylesheet>

Cheers, John Bampton.

Hi John

Good to read you again but the code given by you suppress only comment tag but not content in between <!--E-->I also need to be deleted along with comments<!--/E-->

so according to your code my previous thread exp output would produce

<atlgrp><atl>[B]Text to remove[/B]Inhibition of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation[B]Another text to remove[/B]</atl><runtl>Inhibition [B]one another text to remove[/B]of parkin function in Parkinson&apos;s disease through c-Abl&ndash;mediated tyrosine phosphorylation</runtl></atlgrp>

Text in Bold face also need to be deleted.

Once again thanks for response.

Try with the below:

<xsl:template match="atlgrp">

<xsl:variable name="test">
<xsl:apply-templates/>
</xsl:variable>
<atlgrp>
<xsl:for-each select="$test/*">
<xsl:copy>
<xsl:value-of select="replace(replace(replace(., ' ','*****'),'startinggg([a-zA-Z0-9\*]+)endinggg',''),'\*\*\*\*\*',' ')"/>
</xsl:copy>
</xsl:for-each>
</atlgrp>
</xsl:template>

<xsl:template match="atl">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="runtl">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="//comment()[position() mod 2 = 1]">
<xsl:value-of select="'startinggg'"/>
</xsl:template>

<xsl:template match="//comment()[position() mod 2 = 0]">
<xsl:value-of select="'endinggg'"/>
</xsl:template>

Thanks mrame your code works like charm Thanks Thanks......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.