This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: fill an array in javascript
- From: "Chris Bayes" <chris at bayes dot co dot uk>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 23 Nov 2001 12:47:25 -0000
- Subject: RE: [xsl] fill an array in javascript
- Reply-to: xsl-list at lists dot mulberrytech dot com
Nathalie,
If you are doing what it looks like you are trying to do you just need
<xsl:template name="TitreTexte">
XT_HTML = new Array(<xsl:value-of select="titre"/>,
new Array(
<xsl:for-each select="texte">
"<xsl:value-of select="." />"
</xsl:for-each>
)
)
</xsl:template>
Which will give you an array that looks like
[Title][[FirstText][SecondText][ThirdText]]
Accessed as
var title = XT_HTML[0];
var first = XT_HTML[1][0];
var second = XT_HTML[1][1];
var third = XT_HTML[1][2];
Ciao Chris
XML/XSL Portal
http://www.bayes.co.uk/xml
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Nathalie Pult
> Sent: 23 November 2001 10:43
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] fill an array in javascript
>
>
> 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
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list