Subject: RE: [xsl] error in javascript, that is generated from xsl From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Thu, 7 Mar 2002 10:40:29 -0000 |
>I want to select all the data in the 'col' elements and show the data in >html >tables. But I want to show only a few at a time. Hi, This is like a slideshow problem - displaying a few elements at a time with previous and next buttons. This solution should be enough to get you started. Instead of doing it all in Javascript, we can use a single xsl stylesheet that calls itself each time. It takes a parameter 'pos' that identifies the starting position of the nodes you want to pick out. It then displays nodes[pos] and nodes[pos+1], and a form with the buttons next(pos+1) and prev(pos-1). There a test on param pos to ensure it doesnt go below 1. Note: this stylesheet will apply itself using msxml3 and I noticed your xml had an embedded link - so this will only work if you have msxml3 installed in replace mode. If you dont, simply copy-and-paste the script into a different .htm file (in same directory) and run that first to start the ball rolling. cheers andrew ==stylesheet== ==slideshow.xsl== <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="pos" select="3"/> <xsl:variable name="prev"> <xsl:choose> <xsl:when test="number($pos) > 1"><xsl:value-of select="number($pos)-1"/></xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="next" select="$pos+1"/> <xsl:template match="/"> <html> <head> <title>Transformed data from row-col xml</title> <script language="Javascript"> function applyXSL(pos) { var xml = new ActiveXObject("MSXML2.DOMDocument.3.0") xml.async = false xml.load('slideshow.xml') var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0") xsl.async = false xsl.load('slideshow.xsl') var template = new ActiveXObject("MSXML2.XSLTemplate.3.0") template.stylesheet = xsl processor = template.createProcessor() processor.input = xml processor.addParameter("pos",pos) processor.transform() document.write(processor.output); document.close(); } </script> </head> <body> <xsl:apply-templates/> <form> <button name="prev" onclick="applyXSL('{$prev}')">Prev</button> <button name="next" onclick="applyXSL('{$next}')">Next</button> </form> </body> </html> </xsl:template> <xsl:template match="row"> <xsl:value-of select="column[$pos]"/><br/> <xsl:value-of select="column[$pos+1]"/> </xsl:template> </xsl:stylesheet> ==xml== ==slideshow.xml== <?xml version="1.0" encoding="UTF-8"?> <some_table> <row> <column>A</column> <column>B</column> <column>C</column> <column>D</column> </row> </some_table> -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Shailesh Valvaikar Sent: 06 March 2002 16:47 To: xsllist Subject: [xsl] error in javascript, that is generated from xsl Hello, I have an xml that has 'row', 'column' kinds elements. I want to select all the data in the 'col' elements and show the data in html tables. But I want to show only a few at a time. For this, I read the data into a javascript array and then make manipulations over that array. I have specified an xsl stylesheet with the xml file. If I see the javascript code the way it would have been generated (transformed) it works fine in IE 5.5, but when I try generate the same using an xsl, it gives an error. I have included the javascript code in a CDATA section. The errors are at the places where there are '>' and '<' in the script. This should not happen when the javascript code is in CDATA section. Can anybody point out the problem ? I have tried the same with Netscape 6. This gives no error and no output! Here is the xsl file. --------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <HTML> <HEAD><TITLE>Transformed data from row-col xml</TITLE> <SCRIPT language="Javascript"> <![CDATA[ var current; function displayTable(incr) { current = current + incr; if(current > 4) current = 4; /* reset the current if it exceeds the min-max values */ if(current < 0) current = 0; var tableData=new Array(]]> <xsl:for-each select="column"> "<xsl:value-of select="."/>" </xsl:for-each> <![CDATA[)" var mybody=document.getElementsByTagName("body").item(0); var table = document.getElementsByTagName("TABLE").item(0); mytable = document.createElement("TABLE"); mytablebody = document.createElement("TBODY"); for(j=current ; j < 2+current; j++) { mycurrent_row=document.createElement("TR"); for(i=0; i < 2; i++) { mycurrent_cell=document.createElement("TD"); currenttext=document.createTextNode(tableData[j*2 + i]); mycurrent_cell.appendChild(currenttext); mycurrent_row.appendChild(mycurrent_cell); } mytablebody.appendChild(mycurrent_row); } mytable.appendChild(mytablebody); mybody.appendChild(mytable); mytable.setAttribute("border","2"); } function start() { current = 0; displayTable(0); } ]]> </SCRIPT> </HEAD> <BODY onload="start()"> <form> <button name="prev" onclick="displayTable(-2)">Prev</button> <button name="next" onclick="displayTable(+2)">Next</button> </form> </BODY> </HTML> </xsl:template> </xsl:stylesheet> ----------------------------------- The xml looks somewhat like this ... <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="table_style.xsl"?> <some_table> <row> <column>A</column> <column>B</column> <column>C</column> <column>D</column> </row> ... </some_table> Thanks in advance, Shailesh _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.325 / Virus Database: 182 - Release Date: 2/19/02 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.325 / Virus Database: 182 - Release Date: 2/19/02 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] error in javascript, that, Michael Kay | Thread | [xsl] inline call to external proce, Eric Smith |
Re: [xsl] XPOINTER to HTML by XSL, Jeni Tennison | Date | RE: [xsl] [XSLT] Hyperlink Sort b, Bryan Rasmussen |
Month |