Re: [xsl] template matching

Subject: Re: [xsl] template matching
From: "james walker" <jameswalkerandy@xxxxxxxxxxx>
Date: Fri, 06 Feb 2004 16:17:00 +0000
Yeah its working fine :)
thanks very much for the explanation now, still learning some basic things/shortcuts which i didnt know before! (e.g. dont have to write select="*")
thanks again

From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] template matching
Date: Fri, 6 Feb 2004 16:00:51 GMT

> Please could u explain to me how it works in more detail?
Just this once (since I'm not sure the list's auto-documentation daemon is
actually fully back in working order, although she has been spotted

> Whats steps would be involved in order to create the note list? (not really
> sure why 3 template matches are needed for it?)

The code I posted (plus your template for scope, made well formed:-)
does the trick doesn't it?

explaining how it works:

<xsl:template match="scope"> <xsl:apply-templates select="*" /> </xsl:template>

or even just

<xsl:template match="scope"> <xsl:apply-templates/> </xsl:template>

is going to process all children of scope, so

<xsl:template match="misc">
<p><xsl:value-of select="." /></p>

will do the usual thing and make a p element

we don't want most of the note elements to produce anything (as the
first note element in each bunch is going to generate the whole list) so
have a template that zaps them:

<xsl:template match="note"/>

Now we do want the first of each notes to do something so that's a note
who's immediately preceding element is not a note

<xsl:template match="note[not(preceding-sibling::*[1][self::note])]">

this has higher priority thatn the simple  match="note" so when both
match this template (not the other one) will fire.

Thus template has to make a list and then make the items in it
the items will be made in "note" mode so just apply-templates back to
this node in note mode:

<xsl:apply-templates mode="note" select="."/>

in note mode you should only ever see a note element what you have to do is make a list item, and then process your following sibling if it is a note and stop otherwise:

<xsl:template match="note" mode="note">
<xsl:apply-templates select="following-sibling::*[1][self::note]" mode="note"/>

(you had <lli) there shoudl be ,li) of course.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

XSL-List info and archive:

Tired of 56k? Get a FREE BT Broadband connection

XSL-List info and archive:

Current Thread