www.webdeveloper.com
Results 1 to 5 of 5

Thread: xsl param

Threaded View

  1. #1
    Join Date
    May 2009
    Posts
    2

    xsl param

    Hi, I am having difficulty displaying a variable to represent the percentage of students who receive a particular grade.
    Any help would be greatly appreciated my code is as follows:

    XML:
    <student>
    <first-name>Ulne</first-name>
    <last-name>Douglas</last-name>
    <grade>C</grade>
    </student>
    <student>
    <first-name>Ambrose</first-name>
    <last-name>Tyler</last-name>
    <grade>B</grade>
    </student>
    <student>
    <first-name>Roger</first-name>
    <last-name>Clemens</last-name>
    <grade>A</grade>
    </student>
    <student>
    <first-name>Monroe</first-name>
    <last-name>Hamburger</last-name>
    <grade>A</grade>
    </student>
    </class>

    XSL:
    <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="4.0" />

    <xsl:template name="print_grade">
    <xsl:param name="target_grade" select="''" />
    <xsl:variable name="grade" select="class/student[starts-with(grade,$target_grade)]" />
    <xsl:if test="$target_grade=''" />
    <h1><xsl:value-of select="$target_grade" /></h1>

    <!--
    Number of students receiving grade: <b><xsl:value-of select="count($grade)" /></b>

    Percentage of students receiving grade: <!--I need to print the percentage of students receiving a particular grade variable out of the total students-->
    -->
    </xsl:template>

    <xsl:template match="/">
    <html>
    <head>
    <title>Grade Report</title>
    </head>
    <body>
    <p>
    <xsl:call-template name="print_grade">
    <xsl:with-param name="target_grade" select="'A'"/>
    </xsl:call-template>
    </p>
    <p>
    <xsl:call-template name="print_grade">
    <xsl:with-param name="target_grade" select="'B'"/>
    </xsl:call-template>
    </p>
    <p>
    <xsl:call-template name="print_grade">
    <xsl:with-param name="target_grade" select="'C'"/>
    </xsl:call-template>
    </p>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Last edited by spyro; 05-25-2009 at 05:31 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles