I am working on a small dashboard type set of pages to be used in IE7
(and only IE7). I am now stumbling on one piece of Javascript / XSL
(Version 1.0)
I have a person name field and an associated select html element to
filter the list of names from the xml file. This filter works fine
except for one person's name that contains and apostrophe. I have
tried using replace() function to add in a ' and escaping with a
\ but to no avail. All other name values filter fine, just this one
name.
The error message states :
"Expected token ']' found 'NAME'
//Row[Name='O'-->Callaghan<--']
Should i change the encoding on the xml file itself? The XML is
generated from an MS Excel 2007 workbook
Many thanks
Graham
Reduce versions of file below:
XML (data.xml)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Row>
<Name>Graham</Name>
</Row>
<Row>
<Name>Graham</Name>
</Row>
<Row>
<Name>Graham</Name>
</Row>
<Row>
<Name>Graham</Name>
</Row>
<Row>
<Name>Smith</Name>
</Row>
<Row>
<Name>O'Callaghan</Name>
</Row>
</Root>
XSL (list.xsl)
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="html" />
<xsl:variable name="Rows" select="//Row" />
<xsl:template match="//Root">
<xsl:for-each select="$Rows">
<p><xsl:value-of select="Name" /></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
HTML / Javascript
<html>
<head>
<script language="javascript">
function LoadXML(xmlname)
{
var xmlDOC
xmlDOC = new ActiveXObject("Microsoft.XMLDOM");
xmlDOC.async = false;
xmlDOC.load(xmlname);
return(xmlDOC);
}
function TransformXML(data, xform)
{
xml=LoadXML(data);
xsl=LoadXML(xform);
dataFields = xml.transformNode(xsl);
document.getElementById("divContent").innerHTML=dataFields;
}
function FilterXML(sFilter)
{
filterNode = list.XMLDocument.selectSingleNode("xsl:stylesheet/
xsl:variable[@name='Rows']")
filterNode.setAttribute("select", "//Row[Name='" + sFilter + "']")
dataFields = xml.transformNode(list.XMLDocument)
document.getElementById("divContent").innerHTML=dataFields;
}
</script>
</head>
<body onLoad="TransformXML('data.xml', 'list.xsl')">
<xml id="list" src="list.xsl" />
<select id="cboList" onChange="FilterXML(this.value)">
<option>Select..</option>
<option value="Graham">Graham</option>
<option value="Smith">Smith</option>
<option value="O'Callaghan">O'Callaghan</option>
</select>
<div id="divContent"></div>
</body>
</html>