This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
javascript in XSLT
Hi,
I really have some trouble on my javascript in my stylesheet. What I need to
do in the javascript in my stylesheet is, to access the elements using the
form's name and checkbox's name.
Thanks a lot for your help.
Here are the portions of my stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
version="1.0">
<xsl:output method='html'/>
<xsl:include href="markRecords.xsl" /> <!-- the javascript is in this
stylesheet , attached after this stylesheet-->
<xsl:template match="Results">
<html>
<head>
<title>Search Results </title>
</head>
<xsl:call-template name="markRecords" /> <!-- Here, I am trying to call
the javascript -->
<body>
<xsl:apply-templates select="result">
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="result">
<xsl:variable name="key">
<xsl:value-of select="./Key" />
</xsl:variable>
<form name="results">
<input name="marks" type="checkbox" onClick='saveme("{$key}",
this.checked)' /> <br/>
</form>
</xsl:template>
Here is the markRecords.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template name="markRecords">
<script>
function saveme(key, value) {<![CDATA[
var script, i, num, temp;
num = document.results.length;
alert("total elements is " + document.results.length); // note,
this works just fine, say total elements is 5 ( 5 searching results)
for ( i = 0; i < num; i ++ ) {
temp = document.results.marks[i].type;
// note, results is the name of the form, marks is the name of the checkboxes,
but here is the problem,
// the javascript gives me error:
//document.results.marks[i] has no properties.
alert("element " + i "'s type is " + temp);
}
]]>
</script>
</xsl:template>
</xsl:stylesheet>
Thanks again for your help.
Ming
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list