Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filtering XML using XSL and Javascript - Problem with name containing apostrophe

249 views
Skip to first unread message

Fondaaa

unread,
May 20, 2011, 9:58:44 AM5/20/11
to
Hi all,

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>

ashish...@gmail.com

unread,
Apr 16, 2013, 7:02:08 AM4/16/13
to
Hey this works perfectly on IE but selectsinglenode() function does not support in firefox or other browser. Can someone please provide the implementation for other browers too !!!
0 new messages