Re: [xsl] Can I test the name of the current element?

Subject: Re: [xsl] Can I test the name of the current element?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 30 Jan 2003 23:29:40 GMT
> My apologies if this is in a faq somewhere, I had no luck finding a
> solution there.

searching the faq or the Xpath spec would I'm sure have shown that the
name() function returns the name of the current node.


    <xsl:when test=".=Line"> <!-- something like this -->

that tests the string value of the current node (which is empty for
empty elements) against the string value of the Line child of the
current node (which is empty as these nodes have no children at all)

so you want
    <xsl:when test="name()='Line'"> <!-- something like this -->
which tests the name of the current node against the string 'Line'
but actually it's better to instead do
<xsl:when test="self::Line">
which is simpler and more robust should you ever use namespaces.

alternatively the natural implementation of
> However I need to process them a second time differently:
is to use a mode,
get rid of your xsl:choose and use
<xsl:apply-templates mode="abc"/>
then you just need
<xsl:template match="Line" mode="abc"> L </xsl:template>
<xsl:template match="Curve" mode="abc"> C </xsl:template>

David

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread