|
next
|
Subject: Filtering with XSLT not working anymore Author: Sharon Steringa Date: 04 Sep 2006 10:23 AM
|
Hi everyone!
I have a problem with my XSLT-filtering function: it has stopped working as perfectly as it did a couple of weeks ago and now only returns a blank screen!
The situation:
A context menu in a table on my website gives options to apply a.o. negative and positive filtering on the value of the item clicked. For instance, you right-click the cell displaying the value 'Pig', choose 'Filter on 'Pig'' and the javascript below is activated (modified version of the Bayes tutorial).
Then the transform should take place, as it has done perfectly so many times before... but then a couple of weeks ago I noticed that it didn't work anymore. Since I didn't change a thing in either my javascript, XML or XSL, my guess was that some IE update causes this problem...(on some computers, there is no problem) But then more people should have this problem, yet I couldn't find anything about it on the web. If anyone knows if there's something wrong with my code, or if I can do anything to solve the problem, I would like to hear! Thanks a lot, Debbie.
--------------------------------------------------------------------
function renderData(filterField, filterValue, mode) {
try{
var x = document.XMLDocument;
if (x==null)
{x = navivator.XMLDocument};
var s=loadsheet(mode);
var tem = new ActiveXObject("MSXML2.XSLTemplate.3.0");
tem.stylesheet = s;
var proc = tem.createProcessor();
proc.addParameter('field1',filterField);
proc.addParameter('filter1',filterValue);
proc.input = x;
proc.transform();
var str = proc.output;
var newDoc = document.open("text/html");
newDoc.write(str);
navigator.XMLDocument = x;
navigator.XSLDocument = s;
newDoc.close();
}catch(exception){
}
}
--------------------------------------------------------------------
(loadsheet is a function choosing the appropriate XSL depending on the filter mode (pos, neg) and loading it in a FreeThreadedDOMDocument.3.0)
Here's an example of an XML to be transformed (even the simplest one-column table like this one leaves a blank screen):
--------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<?xml:stylesheet type="text/xsl" href="/lib/xtable/xTable.xsl"?>
<general>
<Appname value=""/>
<data>
<global>
<orderby value=""/>
<clientno value="/lib/xtable/css/0.css"/>
<created value="4-9-2006 11:18:50"/>
</global>
<cols><fdescription caption="Description" color="" width="100" type="text" visible="True"/></cols>
<rows>
<row>
<id value="68"/>
<fdescription value="Clients from Art Systems"/>
<fdatasetname value="CLIENT"/>
<fid value="68"/>
<fdataset value="68"/>
</row>
<row>
<id value="10"/>
<fdescription value="Datasets"/>
<fdatasetname value="DATASET"/>
<fid value="10"/>
<fdataset value="10"/>
</row>
<row>
<id value="12"/>
<fdescription value="Datatypes"/>
<fdatasetname value="DATATYPE"/>
<fid value="12"/>
<fdataset value="12"/>
</row>
<row>
<id value="11"/>
<fdescription value="Fields"/>
<fdatasetname value="FIELDS"/>
<fid value="11"/>
<fdataset value="11"/>
</row>
<row>
<id value="4"/>
<fdescription value="Fieldsettings"/>
<fdatasetname value="FIELDSETTINGS"/>
<fid value="4"/>
<fdataset value="4"/>
</row>
<row>
<id value="5"/>
<fdescription value="Users"/>
<fdatasetname value="USERS"/>
<fid value="5"/>
<fdataset value="5"/>
</row>
</rows>
</data>
<literal_xhtml_footer>
</literal_xhtml_footer>
</general>
--------------------------------------------------------------------
and here's the XSL I use to filter positively (field1 and filter1 are where the parameters are added):
--------------------------------------------------------------------
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" version="1.0" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:decimal-format name="european" decimal-separator="," grouping-separator="."/>
<xsl:param name="data" select="general/data/rows/row"/>
<xsl:param name="cols" select="general/data/cols/*" />
<xsl:param name="sortfield" select="$field1"/>
<xsl:param name="datatype" select="general/data/cols/*[name()=$sortfield]/@type"/>
<xsl:param name="field1" select="'fdescription'"/>
<xsl:param name="filter1" select="'Fields'"/>
<xsl:param name="sortorder" select="'ascending'"/>
<xsl:param name="selectedid" select="$filter1"/>
<xsl:param name="customcss" select="general/data/global/clientno/@value" />
<xsl:variable name="visible-cols" select="$cols[@visible = 'True']"/>
<xsl:variable name="filterData">
<xsl:copy-of select="/general/data/cols"/>
<xsl:apply-templates select="$data/*[name()=$field1 and (translate(@value,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=translate($filter1,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'))] /.." mode="filterData"/>
</xsl:variable>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="{$customcss}"/>
<script src="/lib/js/as.js">
</script>
<script src="/lib/xtable/xTable.js">
</script>
</head>
<body onload_="rowClick({$selectedid});" onkeydown_="bodyKeyDown();">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="data">
<div class="header">
<xsl:copy-of select="./literal_xhtml_header"/>
</div>
<!--top bar-->
<form method="post">
<table class="head">
<tr>
<!-- header, column titles-->
<xsl:call-template name="head"/>
</tr>
</table>
<div class="scroll">
<table>
<!--data, columns-->
<xsl:call-template name="cols"/>
<!--sorting-->
<xsl:choose>
<xsl:when test="$datatype = 'date'">
<!--date sorting-->
<xsl:apply-templates select="msxsl:node-set($filterData)/row">
<xsl:sort select="translate(*[name()=$sortfield]/@value,'T-:','')" order="{$sortorder}" data-type="number"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="msxsl:node-set($filterData)/row">
<xsl:sort select="*[name()=$sortfield]/@value" order="{$sortorder}" data-type="{$datatype}"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</table>
</div>
<div class="footer">
<xsl:copy-of select="../literal_xhtml_footer"/>
</div>
</form>
</xsl:template>
<xsl:template name="head">
<xsl:for-each select="$visible-cols">
<th style="width: {@width};">
<li class="nosort" onclick_="filterClick();" href="{name()}">
<xsl:if test="name()=$sortfield">
<xsl:attribute name="class">
<xsl:value-of select="$sortorder"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="@caption"/>
</li>
</th>
</xsl:for-each>
</xsl:template>
<xsl:template name="cols">
<xsl:for-each select="$visible-cols">
<colgroup span="1" style="width: {@width}; background-color: {@color};"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="row">
<tr onclick_="rowClick();" href="{count(/row)}" id="{id/@value}" ondblclick_="DoubleClick();" onkeydown_="bodyKeyDown();">
<xsl:for-each select="*">
<xsl:if test="/cols/*[name()=name(current())]/@visible='True'">
<xsl:choose>
<xsl:when test="/cols/*[name()=name(current())]/@type='date'">
<td onmousedown_="cellClick();" href1="{name()}" href2="{/cols/*[name()=name(current())]/@caption}" href3="{/cols/*[name()=name(current())]/@type}">
<xsl:if test="./@value!=''">
<xsl:value-of select="substring-after(substring-after(substring-before(./@value,'T'),'-'),'-')"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring-before(substring-after(substring-before(./@value,'T'),'-'),'-')"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring-before(./@value,'-')"/>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(./@value,'T')"/>
</xsl:if>
</td>
</xsl:when>
<xsl:when test="/cols/*[name()=name(current())]/@type='text'">
<td onmousedown_="cellClick();" href1="{name()}" href2="{/cols/*[name()=name(current())]/@caption}" href3="{/cols/*[name()=name(current())]/@type}">
<xsl:value-of select="./@value"/>
</td>
</xsl:when>
<xsl:otherwise>
<td onmousedown_="cellClick();" href1="{name()}" href2="{/cols/*[name()=name(current())]/@caption}" href3="{/cols/*[name()=name(current())]/@type}" href4="{format-number(sum(/row/*[name()=name(current())]/@value[boolean(sum(.))]),'#.###.###,##','european')}">
<xsl:value-of select="./@value"/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template match="row" mode="filterData">
<xsl:copy>
<xsl:copy-of select="id"/>
<xsl:for-each select="*">
<xsl:if test="/general/data/cols/*[name()=name(current())]/@visible='True'">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="literal_xhtml_footer"/>
<xsl:template match="literal_xhtml_header"/>
</xsl:stylesheet>
--------------------------------------------------------------------
|
|
|