Skip to content

Instantly share code, notes, and snippets.

@eerohele
Created September 30, 2015 08:53
Show Gist options
  • Save eerohele/8979e41fc010b8225634 to your computer and use it in GitHub Desktop.
Save eerohele/8979e41fc010b8225634 to your computer and use it in GitHub Desktop.
DITA-OT XSLT stylesheet performance optimization
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//topic[contains(@class, ' concept/concept ')]/body[contains(@class, ' concept/conbody ')][last()]"/>
</xsl:template>
<xsl:template match="topic[contains(@class, ' concept/concept ')]/body[contains(@class, ' concept/conbody ')][last()]">
<xsl:value-of
select="count(preceding::table[contains(@class, ' topic/table ')]/title[contains(@class, ' topic/title ')]) +
count(preceding::fig[contains(@class, ' topic/fig ')]/title[contains(@class, ' topic/title ')])"/>
</xsl:template>
<!-- Average execution time over last 25 runs: 1.456811s (1456.811488ms) -->
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//*[contains(@class, ' concept/concept ')]/*[contains(@class, ' concept/conbody ')][last()]"/>
</xsl:template>
<xsl:template match="*[contains(@class, ' concept/concept ')]/*[contains(@class, ' concept/conbody ')][last()]">
<xsl:value-of
select="count(preceding::*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]) +
count(preceding::*[contains(@class, ' topic/fig ')]/*[contains(@class, ' topic/title ')])"/>
</xsl:template>
<!-- *** Average execution time over last 25 runs: 3.231367s (3231.367094ms) -->
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment