[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: fill an array in javascript
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@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Nathalie Pult > Sent: 23 November 2001 10:43 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|