Subject: [xsl] Dynamic javascript array loading in XSL page. From: sicaudp@xxxxxxxxxxxxxx Date: Tue, 9 Apr 2002 09:35:45 -0700 |
All: First of all, I am an absolute newbie for XSL but I am trying.... I have been tasked with taking over a collection of XSL pages which produce HTML forms. Some of the pages contains script in CDATA blocks and I need to enhance the functionality for some of them. In particular, I need to build small matrices do be displayed in child browser windows. Given that I do not want to use hidden tags, I elected to load a javascript two-dimensional array. So...., given a XML source file similar to the one below, how can I laod the data in the html page? (so I get the 'desired result' below) I have included my first (and second) attempts to do this just for laughs but of course, nothing works. I would really appreciate it if anybody gave me any pointers. In the meantime, I'll just go back to reading Michael's book (excellent but not easy to follow) between training bouts at Zvon.org. (thanks for the pointer Joerg) TIA Patrice XML SOURCE <?xml-stylesheet type="text/xsl" href="ArrayLoadTest.xsl"?> <SRSource> <IndividualSR> <SrID>srid1</SrID> <srothervalue>srothervalue1</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid2</SrID> <srothervalue>srothervalue2</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid3</SrID> <srothervalue>srothervalue3</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid4</SrID> <srothervalue>srothervalue4</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid5</SrID> <srothervalue>srothervalue5</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid6</SrID> <srothervalue>srothervalue6</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid7</SrID> < srothervalue>srothervalue7</srothervalue> </IndividualSR> <IndividualSR> <A8SrID>srid8</A8SrID> <srothervalue>srothervalue8</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid9</SrID> <srothervalue>srothervalue9</srothervalue> </IndividualSR> <IndividualSR> <SrID>srid10</SrID> <srothervalue>srothervalue10</srothervalue> </IndividualSR> </SRSource> DESIRED RESULT <script type="text/javascript" language="JavaScript"> var SRArray = new Array[10]; SRArray [1] = new Array[10]; SRArray [2] = new Array[10]; SRArray [3] = new Array[10]; SRArray [4] = new Array[10]; SRArray [5] = new Array[10]; SRArray [6] = new Array[10]; SRArray [7] = new Array[10]; SRArray [8] = new Array[10]; SRArray [9] = new Array[10]; SRArray[10] = new Array[10]; SRArray [1][1] = 'srid1' SRArray [1][2] = 'srothervalue1' SRArray [2][1] = 'srid2' SRArray [2][2] = 'srothervalue2' SRArray [3][1] = 'srid3' SRArray [3][2] = 'srothervalue3' . . . </script> MY FIRST LAUGHABLE ATTEMPT AT RESOLVING THE PROBLEM. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <!-- *** Sicaud 04-03-02 Start Changes --> <html> <head> <title> <xsl:value-of select="title"/> </title> <script type="text/javascript" language="JavaScript"> var SRArray = new Array[10]; SRArray [1] = new Array[10]; SRArray [2] = new Array[10]; SRArray [3] = new Array[10]; SRArray [4] = new Array[10]; SRArray [5] = new Array[10]; SRArray [6] = new Array[10]; SRArray [7] = new Array[10]; SRArray [8] = new Array[10]; SRArray [9] = new Array[10]; SRArray[10] = new Array[10]; <xsl:variable name="NodeToProcess" select="//"/> <xsl:variable name="outerArrayCount" select="count($NodeToProcess)"/> --> <xsl:for-each select="//SRSource/*">--> <xsl:apply-templates select="//SrSource"/> <xsl:variable name="outerArrayIndex" select="position()"/> <xsl:for-each select="$NodeToProcess[$outerArrayIndex]/*"> <xsl:variable name="innerArrayIndex" select="position()"/> </xsl:for-each> </xsl:for-each> <!-- *** Sicaud 04-03-02 End Changes --> </script> </head> <body/> </html> </xsl:template> <xsl:template match="SrSource"> <xsl:for-each select="./*"> <xsl:apply-templates select="//innerProcessing" mode="javascript"/>--> <xsl:param name="node" select="."/> </xsl:for-each> SRArray [<xsl:value-of select="$node"/>] = "<xsl:value-of select="."/>"; SRArray [<xsl:value-of select="$node"/>][<xsl:value-of select="position()"/>] = "<xsl:value-of select="."/>"; </xsl:template> <xsl:template name="innerProcessing" match="IndividualSR"> <xsl:param name="node" select="."/> <xsl:for-each select="./*"> SRArray [<xsl:value-of select="$node"/>][<xsl:value-of select="position()"/>] = <xsl:value-of select="."/> </xsl:for-each> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Business logic (was: Re: [xsl] , Michael Kay | Thread | Re: [xsl] Dynamic javascript array , Robert Koberg |
RE: [xsl] XSLT processor based on S, Rick Geimer | Date | [xsl] Re: Efficiency Issues, Dimitre Novatchev |
Month |