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

Re: Beginner XSL question

Subject: Re: Beginner XSL question
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 16 May 2002 13:50:23 -0600 (MDT)
stevenson s template body
Arturo C wrote:
> Hi and sorry my english... how can i count the number of elements, for 
> instance, student in the following case:
> 
> <school>
>    <student>
>       ....
>    </student>
>    <student>
>       ....
>    </student>
>    <student>
>       ....
>    </student>
> </school>
> 
> and show the result (3) in an HTML page using XSL?

To get you started, and to demonstrate several principles, here is an example.
It assumes each <student> contains a <name>. You should get a good book on
XSLT. Try these:

  http://www.amazon.com/exec/obidos/ASIN/1861005946
  http://www.amazon.com/exec/obidos/ASIN/1861005067

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>test</title>
      </head>
      <body>
        <h1>test</h1>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="school">
    <p>There are <xsl:value-of select="count(student)"/> students.</p>
    <ul>
      <xsl:apply-templates select="student"/>
    </ul>
  </xsl:template>

  <xsl:template match="student">
    <li>
      <xsl:value-of select="concat('Student #',position(),' of ',last(),': ',name)"/>
    </li>
  </xsl:template>

</xsl:stylesheet>

 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.