2006-07-03

XSLT Decorator Pattern

As usual with patterns - read and surprised: «Oh, it's a pattern... and I always did so...».

True, the variant with a default variable a little bit more flexible.

The idea was taken from here. However, their snippet does not work.
The correct variant:
<!-- html output -->
<xsl:template name="html-wrapper">
<xsl:param name="contents">
<xsl:apply-templates/>
</xsl:param>
<xsl:result-document method="html" indent="yes" href="{concat(local-name(),'_',@name,'.html')}">
<html><body>
<xsl:copy-of select="$contents"/>
</body></html>
</xsl:result-document>
</xsl:template>

<xsl:template match="Chapter">
<xsl:call-template name="html-wrapper">
<xsl:with-param name="contents">
<-- some context there-->
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template match="Part">
<xsl:call-template name="html-wrapper">
<xsl:with-param name="contents">
<-- some context there-->
</xsl:with-param>
</xsl:call-template>
</xsl:template>

and so on

No comments:

Post a Comment