xsl-list
[Top] [All Lists]

RE: Selecting only one element using templates

2003-12-01 05:46:16

I was able to find the solution to my problem:

<xsl:template match="class[class]">
        <xsl:apply-templates select="class"/>
    </xsl:template>

    <xsl:template match="class">
        <xsl:element name="option">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

Quite how this selects elements called <name> is beyond me...


I did not know you could use a select attribute when applying 
templates. But this leaves me with a question: If I left 
"select" out of the apply-templates xsl element, I would have 
thought it would only apply the templates that I defined. 
Does the processor output all nodes anyway? In other words, 
if I put in an "apply-templates" element, and I have no 
templates defined for a particular node (or set?), why do I 
get output?


There is a built-in template rule for nodes that are not matched by an
explicit template rule. This rule does a recursive apply-templates for
element nodes, and for text nodes it outputs the content. If you want to
override this, write a rule such as:

<xsl:template match="*"/>

Michael Kay


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