XML:
<root>
<a>This is first para [[the first para1]]</a>
<a>This is second para [[the second para2]]</a>
</root>
XSLT 2.0 I tried:
<xsl:template match='@* | node()'>
<xsl:copy>
<xsl:apply-templates select='@* | node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[contains(text(),'[[')]"></xsl:template>
Expected result:
<root>
<a> This is first para</a>
<a> This is second para</a>
</root>
Thank you in advance for help.
>Solution :
This could do it for you in XSLT 2.0. Please note that in your sample input, the second text entry is missing the finishing ‘]]’.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
exclude-result-prefixes="#all">
<xsl:template match='@* | node()'>
<xsl:copy>
<xsl:apply-templates select='@* | node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:sequence select="replace(., ' [\[][\[].*\]\]', '')" />
</xsl:template>
</xsl:stylesheet>
In the event that the missing ‘]]’ in the second entry is intentional, you could make the ending ‘]]’ optional in the match pattern:
<xsl:template match="text()">
<xsl:sequence select="replace(., '[\[][\[].*(\]\])?', '')" />
</xsl:template>
This latter provides this output with your given input:
<root>
<a>This is first para </a>
<a>This is second para </a>
</root>