Re: [xsl] Finding the current node type

Subject: Re: [xsl] Finding the current node type
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 31 Jul 2007 00:07:40 +0100
you don't mean node type which means (in xpath parlance)  "element" or
"comment" etc. You want the node name test, along the self axis rather
than the default child axis, so

		<xsl:when test="self::speaker">

note however that dowing a big xsl:choose matching on node names is just
a poor man's version of template matching. If there are only two cases
it doesn't really matter but it's usually more efficient to use template
matching as the system will (probably) have some efficient hashed switch
on element names, but an xsl:choose probably implies a sequential set of
tests so time proportional to the number of cases.

so you could code it as

<xsl:apply-templates match="speaker|laptop"/>

<xsl:template match="speaker">
	<!-- Assign a sequential Number -->
	Item No: <xsl:value-of select="position()"/> <br />
	<!-- Now output item-specific details -->
			RMS Power: <xsl:value-of select="rms_power"/>
<br />
			Peak Power: <xsl:value-of select="peak_power"/>
<br />	


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread