Page 1 of 1

using AND operator

Posted: Sat Jun 02, 2012 5:16 am
by gungy
hiya,

how can i get two recursive calls in my template to evaluate my constraint using the AND operator?

xml file structure:

<filterML>
<constraint>
<and> <!-- 2 conditions -->
<operator operation="="> <!-- condition1: get all subjects evaluatung to chemistry -->
<input>subject</input>
<value>chemistry</value>
</operator>
<operator operation="<"> <!-- condition2: get all age < 70 -->
<input>age</input>
<value>70</value>
</operator>
</and>
</constraint>
</filterML>


stylesheet:

<xsl:template name="evaluateFilterML">
<xsl:param name="operator" />
<xsl:param name="input" />
<xsl:param name="value" />
<xsl:choose>
<xsl:when test="$operator = 'equal'">
<xsl:value-of select="$input = $value"/>
</xsl:when>
<xsl:when test="$operator = 'not equal to'">
<xsl:value-of select="$input != $value"/>
</xsl:when>
<xsl:when test="$operator = 'less than'">
<xsl:value-of select="$input < $value"/>
</xsl:when>
<xsl:when test="$operator = 'greater than'">
<xsl:value-of select="$input > $value"/>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="/">
<xsl:param name="currentyear" select="2012" />
<xsl:call-template name="evaluateFilterML">
<xsl:with-param name="operator" select="//filterML/constraint/and/operator[@operation='=']" />
<xsl:with-param name="input"> <!-- recursively evaluate input value -->
<xsl:apply-templates select="//citizensOfBritik/citizen/education/qualification[subject='chemistry']" />
</xsl:with-param>
<xsl:with-param name="value"> <!-- recursively evaluate condition value -->
<xsl:apply-templates select="($currentyear - (substring((dob),1,4))) < 70" />
</xsl:with-param>
</xsl:call-template>
</xsl:template>


--- so i need my stylesheet to output:
<xsl:apply-templates select="//citizensOfBritik/citizen/education/qualification[subject='chemistry']" /> AND <xsl:apply-templates select="($currentyear - (substring((dob),1,4))) < 70" />