xsl-list
[Top] [All Lists]

Re: [xsl] fallback to a default template in xsl processing

2008-04-25 06:08:45
                                       

 <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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--