[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: template matching
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|