The book structure is just a simlified example to show what I'm doing but anyway it has around 2500-3000 <ook>and many more element inside <book>node, which I purposely did not put here.
Also, I'm doing some more trimming of spaces apart from what I stated as condition here like removing whitespace node with <xsl:strip-space elements="."> and removing preceding and trailing spaces with normalize-space function.
Here is the stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()" mode="strip-all">
<xsl:copy>
<xsl:apply-templates mode="strip-all"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()" mode="strip-some">
<xsl:copy>
<xsl:apply-templates mode="strip-some"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()" mode="strip-quad">
<xsl:copy>
<xsl:apply-templates mode="strip-quad"/>
</xsl:copy>
</xsl:template>
<xsl:template match="book[topic='Biology']">
<xsl:copy>
<xsl:apply-templates mode="strip-quad"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="strip-quad">
<xsl:value-of select="normalize-space()"></xsl:value-of>
</xsl:template>
<xsl:template match="book[topic='programming'] | book[topic='Computers']">
<xsl:copy>
<xsl:apply-templates mode="strip-all"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="strip-all">
<xsl:strip-space elements="."></xsl:strip-space>
<xsl:value-of select="translate(normalize-space(.), ' ', '')"/>
</xsl:template>
<xsl:template match="book[topic='Literature']">
<xsl:copy>
<xsl:apply-templates mode="strip-some"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()[not(contains(preceding::text()[1], 'Lang'))]" mode="strip-some">
<xsl:value-of select="translate(., ' ', '')"/>
</xsl:template>
</xsl:stylesheet>
|