Re: [xsl] Selecting only one element using templates

Subject: Re: [xsl] Selecting only one element using templates
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Mon, 01 Dec 2003 23:32:04 +1300
Hello,

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>


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?

I think this is where my confusion lies, and isn't really explained in
simple terms anywhere I have looked.

Regards,

/johnny :)


On 1/12/03 9:59 PM, "JCS" <subscriber@xxxxxxxxxxxxx> wrote:

> Hello,
> 
> I'm new to XSL/T and I've been reading the list archives, the tutorials
> available in and around the net, etc., but I can't seem to find an answer to
> a simple question (which is usually the case with simple "abstract"
> questions) so I hope nobody minds if I ask here.
> 
> I've got an XML structure as so:
> 
> <name></name>
> <name></name>
> <name>
> <name></name>
> <list>
> <item></item>
> <list>
> </name>
> <name></name>
> 
> Now, I've been able to get at what I want using the examples provided by
> this list, so I'm not having difficulty with the more intermediate steps,
> however, I'm having difficulty getting my head this:
> 
> What if I just want to select the <name> node? If I use
> <xsl:apply-templates/> and select "name" I get all name elements, plus the
> item element which I don't want. I just want a list of names from the name
> elements.
> 
> Do I have to specify a template for each element in an XML document? That
> seems rather tedious, especially if I have a lot of elements within <name>
> elements used as containers.
> 
> Any help is appreciated,
> 
> TiA,
> 
> /johnny :)

-- 
"You cannot discover new oceans unless you have the courage to lose sight
 of the shore." 


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


Current Thread