[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: template matching

Subject: Re: template matching
From: Peter Flynn <pflynn@xxxxxx>
Date: Wed, 04 Feb 2004 14:33:02 +0000
parent note template
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.