<?xml version="1.0" encoding="UTF-8"?>
<!-- xslt stylesheet -->
<xsl:stylesheet version="1.0"
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
xmlns:sdp="[URL unfurl="true"]http://www.sectornet.co.uk/2004/DocPro">[/URL]
<xsl:output method="html"/>
<xsl:variable name="mergeData" select="document('merge-data.xml')//dataset"/>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="/">
<html>
<head>
<title>condition test output.</title>
</head>
<body>
<center>
<h1>Condition Test.</h1>
</center>
[b]<xsl:apply-templates select="doc/page/content"/>[/b]
</body>
</html>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="para">
<p>
[b]<xsl:apply-templates/>[/b]
</p>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="text">
[b]<xsl:apply-templates/>[/b]
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="condition">
<xsl:variable name="curNode" select="."/>
<xsl:text> (CONDITION) </xsl:text>
<xsl:choose>
<xsl:when test="$curNode/@eval = 'ELSE'">
<!-- process else statement -->
<xsl:variable name="prevIfNode" select="$mergeData/condition[@ref = substring-after($curNode, '<<ELSE>>')]"/>
<xsl:if test="$prevIfNode = 'TRUE'">
<!-- go to end tag -->
[b]<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $prevIfNode/@eval)]"/>[/b]
</xsl:if>
</xsl:when>
<xsl:when test="$curNode/@eval != 'END'">
<!-- process if statement -->
<xsl:variable name="curIfNode" select="$mergeData/condition[@ref = $curNode]"/>
<xsl:if test="$curIfNode != 'TRUE'">
<xsl:choose>
<xsl:when test="ancestor::*/following::*/condition/text() = concat('<<ELSE>>', $curNode)">
<!-- go to else tag -->
[b]<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ELSE>>', $curNode)]"/>[/b]
</xsl:when>
<xsl:otherwise>
<!-- go to end tag -->
[b]<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $curNode)]"/>[/b]
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>