[xsl] using mode in multiple template match conditions will improve speed?

Subject: [xsl] using mode in multiple template match conditions will improve speed?
From: "Karlmarx Rajangam" <karlmarx.rajangam@xxxxxxxxxxxxxxxxxx>
Date: Thu, 3 May 2007 05:04:11 -0400
Hi,

My question is about improving my code. Basically my xml (stipped down)
looks like


	<QUESTION ID="12" MAX="1" TOPIC="Question samples">
		<CONTENT TYPE="text/html">multiple choice</CONTENT>
		<ANSWER QTYPE="MC" MAXRESPONSE="1">
			<CHOICE ID="1">
				<CONTENT TYPE="text/html">1</CONTENT>
			</CHOICE>
			<CHOICE ID="2">
				<CONTENT TYPE="text/html">2</CONTENT>
			</CHOICE>
			<CHOICE ID="3">
				<CONTENT TYPE="text/html">3</CONTENT>
			</CHOICE>
		</ANSWER>
	</QUESTION>
	<QUESTION ID="13" />
		<CONTENT TYPE="text/html">Fill in the blanks</CONTENT>
		<ANSWER QTYPE="FIB"  ...>
			and so on with its corresponding sibling nodes
		</ANSWER>
	</QUESTION>

and in the xslt, we are using lot conditional checkes at the passing
side [reason - different <div class> values for each QTYPE) as well as
at the receiveing side of my xsl file.



and then the xslt

	<xsl:template match="ANSWER">
		<xsl:when test="@QTYPE='MC'">
			<div class="q_mc"><!-- different class names-->
				<xsl:apply-templates/>
			</div>
		</xsl:when>
		<xsl:when test="@QTYPE='TF'">
			<div class="q_tf">
				<xsl:apply-templates/>
			</div>
		</xsl:when>
		+ another 15 such conditions

and the receiving ends are like this

	<xsl:template match="ANSWER[@QTYPE='MC']/CHOICE">
		<div class="q_mc">
			<input type="radio" class="q_RADIO_mc">
				<xsl:attribute
name="name">answer_<xsl:value-of select="../@QTYPE"/>_<xsl:value-of
select="someothervalues"/></xsl:attribute>
				<xsl:attribute
name="value"><xsl:value-of select="./@ID"/></xsl:attribute>
			</input>
			<xsl:apply-templates/>
		</div>
	</xsl:template>

	<xsl:template match="ANSWER[@QTYPE='FIB']/CHOICE">
		and so on....
	</xsl:template>


Now I was wondering

1. whether using MODE like <xsl:apply-templates mode="MC"/> at the start
and <xsl:template match="ANSWER[@QTYPE='MC']/CHOICE" mode="MC"> at the
receiving side will speed up things? - Assuming this will stop checking
every template to find the matching condition.

2. Can I replace multiple choose-when by doing something like?

	<xsl:template match="ANSWER">
		<div>
			<xsl:attribute name="class">q_<xsl:value-of
select="@QTYPE"/></xsl:attribute>
			<xsl:apply-templates/>
		</div>
	</xsl:template>

	where the div class name is now set dynamically.

3. If yes to point (2), will adding translate will offset any gains? - I
mean as a better practice, i may have to use translate to convert class
names q_MC to q_mc even though css i believe is case in-sensitive or
update my css from q_mc to q_MC - but this has other practical problems.

Thanks in advance
karl

Current Thread