This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
fill an array in javascript
- From: Nathalie Pult <s9292251 at access dot unizh dot ch>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 23 Nov 2001 11:43:13 +0100 (MET)
- Subject: [xsl] fill an array in javascript
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi
I have to create an array and fill it with some text chosen out of an
xml-file.
A javascript-function() calls a named template that should get the wanted
text()-Elements out of the .xml.
But I have problems with variables and their concat-function, and I'm not
sure if the whole template will work.
Thanks for helping!
Nathalie
I have the following code for the .xsl:
<?xsl version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
encoding="UTF-8" method="xml" version="4.0" indent="no" media-type="text/html"/>
<xsl:template match="/">
<html>
<head>
<title>xml-generated module</title><script
type="text/javascript" language="JavaScript">
funcition init() {
<xsl:call-template name="TitreTexte"/>
}
[...] some more javascript
</script>
</head>
[Frameset
</html>
</xsl:template>
<xsl:template name="TitreTexte">
<xsl:text>var XT_HTML = new Array(10);</xsl:text>
<!--how can I create an Array whitout knowing the
exact amount
of items?-->
<xsl:variable name="firstArray">
<xsl:for-each
select="//texte_initial/titre[position() > 1]">
<xsl:text>XT_HTML[position()] = new
Array(2);</xsl:text>
<xsl:variable
name="selectedTitle" select="text()">
<xsl:variable
name="firstArray" select="concat('XT_HTML[' , position(), '][1]='',
$selectedTitle, ''')"></xsl:variable>
<xsl:value-of
select="$firstArray"/>
</xsl:variable>
<xsl:variable name="selectedTexts">
<xsl:value-of
select="../texte[1]/text()"/>
<xsl:for-each
select="../texte[position() > 1]">
<xsl:value-of
select="text()"/>
</xsl:for-each>
<xsl:variable
name="secondArray" select="concat('XT_HTML[', position(),'][2]='',
$selectedTexts, ''')"></xsl:variable>
<xsl:value-of
select="$secondArray"/>
</xsl:variable>
</xsl:for-each>
</xsl:variable>
</xsl:template>
</xsl:stylesheet>
And the .xml that goes with:
<?xml version="1.0" encoding="UTF-8"?>
<modul>
<phonetique>
<lecon id="10">
<texte_initial id="11">
<titre>Title</titre>
<texte>FirstText</texte>
<texte>SecondText</texte>
<texte>ThirdText</texte>
</texte_initial>
</lecon>
</phonetique>
</modul>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list