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

RE: XSL function help required

Subject: RE: XSL function help required
From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx>
Date: Fri, 21 Jul 2000 08:53:09 +0300
xsl function 1.0
hi

> I presently have an XML tag stored as so:
>
> <rating> 7 </rating>
>
> It is essentially for rating a product out of a possible score of 10.
>
> What I want to do is to convert it like this:
>
> Rating: 1 2 3 4 5 6 7 8 9 10
>
> where the "7" will be made BOLD.
>
> If the rating were 5, the same string has to be generated, except
> that this
> time, the 5 must be made bold.
>
> Does anyone have an idea about how I'd do this with XSL?

as always - this will do it, but probably someone will come up with a
oneliner :P

[c:\temp]type test.xml
<?xml version="1.0"?>
<rating> 7 </rating>

[c:\temp]type test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/xhtml">

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

<xsl:variable name="rating" select="normalize-space(rating)" />

<xsl:template match="/">
  <html>
    <head><title></title></head>
    <body>
      <xsl:call-template name="KMFDM">
        <xsl:with-param name="counter" select="1" />
      </xsl:call-template>
    </body>
  </html>
</xsl:template>

<xsl:template name="KMFDM">
  <xsl:param name="counter" />
  <xsl:if test="$counter &lt; 11">
    <xsl:choose>
      <xsl:when test="$counter = $rating">
        <b>
          <xsl:value-of select="$counter" />
        </b>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$counter" />
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> </xsl:text>
    <xsl:call-template name="KMFDM">
      <xsl:with-param name="counter" select="$counter + 1" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

[c:\temp]saxon test.xml test.xsl
<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title/>
   </head>
   <body>1 2 3 4 5 6 <b>7</b> 8 9 10 </body>
</html>

and if someone knows what KMFDM stands for, you've made me smile

--
Jarno Elovirta     jarno.elovirta@xxxxxxxxxxxxxx
CODEONLINE Ltd.    http://www.codeonline.com
P.O. Box 538 (Ukonvaaja 2 A), FIN-02130 Espoo, Finland
Mobile: +358 40 772 6785 Fax: +358 9 4393 0410

"Hoc non credo; toga mea surrepta est iterum!"


 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.