cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ivan" <ifon...@latinia.com>
Subject Random selection from XML applying XSL with JS function
Date Fri, 22 Dec 2000 13:07:46 GMT
Hi all!

I want to get a random output from an xml file applying an XSL,
but don't know how to call the Javascript function to get the random
number appear. Any help would be welcomed.
XML Data File (brands.xml)
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="brands.xsl"?>
<?cocoon-process type="xslt"?>
<brands>
<car>BMW</car>
<car>Mercedes</car>
<car>Opel</car>
<car>Porsche</car>
<car>Ferrari</car>
<car>Renault</car>
<car>Citroën</car>
<car>Seat</car>
<car>VolksWagen</car>
<car>Audi</car>
<car>Saab</car>
<car>Toyota</car>
<car>Nissan</car>
<car>Subaru</car>
<car>Lamborghini</car>
</brands>

_____________________________________________________
XSL to output random flower (brands.xsl)
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<script language="javascript">
function getRandom(){
return (Math.round(Math.random()*(count(car)))
}
</script>
<xsl:template match="brands">
<xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>

<html>
<head>
<title>Random</title>
</head>
<body>
There are <xsl:value-of select="count(car)" /> car brands in the list.<br /><br
/>
<xsl:for-each select="car">
<xsl:apply-templates select="." />
<br />
</xsl:for-each>
<br />
<xsl:param name="selectedCar" select="getRandom()"/>
Selected car brand number is:<xsl:copy-of select="$selectedCar"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

_____________________________________________________
Resulting HTML Output
There are 15 car brands in the list.

BMW
Mercedes
Opel
Porsche
Ferrari
Renault
Citroën
Seat
VolksWagen
Audi
Saab
Toyota
Nissan
Subaru
Lamborghini

Selected car brand number is: <number_of_random_selection>

_____________________________________________________

Then I wold like to get the string in xml file that is equal to the
number of this selection, but don't know how to do it as well

Anyway to do this for XSL instead of Javascript function?¿

Thanks very much in advance for any help that could point me
in the right way.

Ivan

Mime
View raw message