Subject: RE: [xsl] fallback to a default template in xsl processing From: "Daly, April" <april@xxxxxxxxxxx> Date: Fri, 25 Apr 2008 14:51:04 +0100 |
Hi David - thanks! that is really great. if you don't mind a follow-up question. with regards to: <!-- nodes following an initial subroutine or list are discarded --> <xsl:template match="*[preceding-sibling::*[last()][self::SUBROUTINE or self::LIST]]"/> if the number of nodeNames to include in: [self::SUBROUTINE or self::LIST] gets large is it ok to just keep adding to the expression? e.g., [self::SUBROUTINE or self::LIST or self::PRODUCT or self::SAMPLE or ....] (a more pie in the sky thought - can a match rule be based on xsl nodes in the current xsl doc?) Thanks for your help! best, april -----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Friday, April 25, 2008 9:07 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] fallback to a default template in xsl processing <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, David Carlisle | Thread | Re: [xsl] fallback to a default tem, David Carlisle |
Re: [xsl] fallback to a default tem, David Carlisle | Date | Re: [xsl] fallback to a default tem, David Carlisle |
Month |