Subject: Re: [xsl] template matching From: Peter Flynn <pflynn@xxxxxx> Date: Wed, 04 Feb 2004 14:33:02 +0000 |
On Wed, 2004-02-04 at 13:26, james walker wrote: > 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 <xsl:template match="//note"> <li> <xsl:apply-templates/> </li> </xsl:template> That will reproduce all <note> elements no matter where they are in the document. If you want to restrict it to notes within those three parents only, use match="//note[parent::sub1 or parent::sub2 or parent::sub3]". If they have some hierarchical meaning where they are, use something like this to divide them: <xsl:template match="//note"> <xsl:choose> <xsl:when test="parent::sub1"> <li> <xsl:apply-templates/> </li> </xsl:when> <xsl:when test="parent::sub2"> <li> <xsl:apply-templates/> </li> </xsl:when> <xsl:when test="parent::sub2"> <li> <xsl:apply-templates/> </li> </xsl:when> </xsl:choose> </xsl:template> ///Peter XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] template matching, james walker | Thread | Re: [xsl] template matching, David Carlisle |
RE: [xsl] template matching, Varley, Roger | Date | [xsl] Get all the node as text, Lionel Crine |
Month |