Subject: Re: [xsl] fallback to a default template in xsl processing From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 25 Apr 2008 14:07:22 +0100 |
<xsl:when test="name(LIMS/*)='SUBOUTINE' or name(LIMS/*)='LIST' "> It's generally a bad idea to test on name() like this. It may not work at all if namespaces are used in teh source, and it is likely to be a lot less efficient than simply matching on the name. test="name(LIMS/*)='SUBOUTINE' is an error in XPath2 (if there is more than one child) and in Xpath 1 it just tests if the first child has name SUBROUTINE which could more efficiently be written test="*[1][self::SUBOUTINE] or if you really want to ask if _any_ child is SUBOUTINE then test="SUBOUTINE" But you do not need a test at all here, just replace <xsl:choose> <xsl:when test="name(LIMS/*)='SUBOUTINE' or name(LIMS/*)='LIST' "> <xsl:apply-templates select="LIMS/*[1]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates mode="default" select="LIMS/*"/> </xsl:otherwise> </xsl:choose> by <xsl:apply-templates select="LIMS/*"/> together with <xsl:template match="*"> usual case </xsl:template> <xsl:template match="SUBOUTINE"> SUBOUTINE case </xsl:template> <xsl:template match="LIST"> SUBOUTINE case </xsl:template> <!-- nodes following an initial subroutine or list are discarded --> <xsl:template match="*[preceding-sibling::*[last()][self::SUBROUTINE or self::LIST]]"/> > Ultimately I would like to 'call' a named template for specific > matched node, why? that just makes the stylesheet more complicated for no benefit. If you want the template to be triggered by the presence of an element use template matching, not named templates. David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] fallback to a default tem, Daly, April | Thread | RE: [xsl] fallback to a default tem, Daly, April |
RE: [xsl] fallback to a default tem, Daly, April | Date | RE: [xsl] fallback to a default tem, Daly, April |
Month |