RE: [xsl] template matching

Subject: RE: [xsl] template matching
From: cknell@xxxxxxxxxx
Date: Wed, 04 Feb 2004 09:45:06 -0500
If your sample actually represents your input, you could create a template that matches a node based on a substring of the node's name.

<xsl:template match="*[substring(name(),1,3)='sub']">
<ul>
<xsl:apply-templates select="note" />
</ul>
</xsl:template>

Of course, if your element names have nothing in common that can be described with substring(), you will have to make one template for each.

-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     james walker <jameswalkerandy@xxxxxxxxxxx>
Sent:     Wed, 04 Feb 2004 13:26:30 +0000
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  [xsl] template matching

if i have a note elemtn that can be placed in side many different elements 
within an xml document e.g.

<main>
<sub1><note></note><note></note><note></note></sub1>
<sub2></sub2>
<sub3><note></note></sub3>
<sub4><note></note><note></note><note></note><note></note></sub4>
<sub5></sub5>
</main>

If i wanted to produce a list of notes when the note element appears i would 
do something like this:

<xsl:template match="sub1">
<ul>
<xsl:apply-templates select="note" />
</ul>
</xsl:template>

<xsl:template match="sub3">

<xsl:template match="sub4">
</xsl:template>

<xsl:template match="note">
<li><xsl:value-of select="note" /></li>
</xsl:template>


Is there anyway i can reduce this code down because i have this implemented 
on a much larger scale where the note element appears within 28-30 other 
elements. Is there anyway to reproduce the output which the design above 
creates without having to write out <ul> tags within each template match?

cheers
james

_________________________________________________________________
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo


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




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


Current Thread