Is it possible to pass parameters to a match Xpath (is this an Xpath sentence?) sentence?
I am using XML data Islands on IE 6.0, I want to apply the following XSLT to the XML.
by the way, the javascript functions are from an article written by Kurt Cagle, XML Pro
at this link
The following sentence works, but shows in the XSLT desired format only the one that fits in the criteria, and shows all the other ones like too ! only that in no format, just firstnames and lastname, no ID
<xsl:template match="record[firstname='Daren']">
I have stated 2 parameters wich are
<xsl
aram name="filterColumn" select="'firstname'"/>
<xsl
aram name="filterValue" select="'Daren'"/>
I would like to use something like this, in order to later be able to pass any filter criteria
<xsl:template match="record[$filterColumn=$filterValue]">
but it just doesn't works, the browser gives me the following error
<b>Error: Variables may not be used within this expression</b>
And another thing, I would like that on the body onload event, I could call the function wich passes the parameters but with a Wildcard, so It would display all the records, currently I do this on body onload
<body onload="filterRecords('firstname','Daren')">
Is it possible to do something like
<body onload="filterRecords('firstname','*')">
first things first, here bellow I put the entire code, any help will be appreciated
<html>
<head>
<title>Sorting and Filtering Records</title>
</head>
<!--
<body onload="showRecords('id','ascending')">
-->
<body onload="filterRecords('firstname','Daren')">
<script language="Javascript">//<![CDATA[
function call(xslIsland,xmlIsland){
var xslDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
;
var rsltDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
;
var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate"
;
xslDoc.async = false;
rsltDoc.async = false;
xslDoc.load(xslIsland.XMLDocument);
xslTemplate.stylesheet=xslDoc;
var xslProc=xslTemplate.createProcessor();
xslProc.input=xmlIsland.XMLDocument;
xslProc.output=rsltDoc;
if (arguments.length >2 && arguments.length % 2 == 0){
for (var i=0;
i<Math.floor((arguments.length)/2)-1;
i++){
paramName=arguments[2*i+2];
paramValue=arguments[2*i+3];
xslProc.addParameter(paramName,paramValue);
}
}
xslProc.transform();
return rsltDoc;
}
function showRecords(sortKey,sortOrder){
var htmlDoc=
call(_ShowRecords,records,"sortKey", sortKey,"sortOrder",sortOrder);
window.container.innerHTML=htmlDoc.xml;
}
function filterRecords(filterColumn,filterValue){
var htmlDoc=
call(_FilterRecords,records,"filterColumn", filterColumn,"filterValue",filterValue);
window.container.innerHTML=htmlDoc.xml;
}
//]]></script>
Filters: <button onclick="filterRecords('firstname','Daren')">First Name = Daren</button><hr>
Sorting: <button onclick="showRecords('firstname',SortOrderList.value)">First Name</button>
<button onclick="showRecords('lastname',SortOrderList.value)">Last Name</button>
<button onclick= "showRecords('id',SortOrderList.value)">User ID</button>
<select name="SortOrderList" id="SortOrderList" value="ascending">
<option value="ascending" selected="selected">Ascending</option>
<option value="descending">Descending</option>
</select><hr>
<div id="container"></div>
<xml id="records">
<records>
<record id="101">
<firstname>Kurt</firstname>
<lastname>Cagle</lastname>
</record>
<record id="102">
<firstname>Aleria</firstname>
<lastname>Delamare</lastname>
</record>
<record id="103">
<firstname>Steven</firstname>
<lastname>Dallas</lastname>
</record>
<record id="104">
<firstname>Opus</firstname>
<lastname>Penguin</lastname>
</record>
<record id="105">
<firstname>Gina</firstname>
<lastname>Alacava</lastname>
</record>
<record id="106">
<firstname>Dean</firstname>
<lastname>Stanton</lastname>
</record>
<record id="107">
<firstname>Corey</firstname>
<lastname>Johnson</lastname>
</record>
<record id="108">
<firstname>Edgar</firstname>
<lastname>Marseiz</lastname>
</record>
<record id="109">
<firstname>Daren</firstname>
<lastname>Malecevitz</lastname>
</record>
<record id="110">
<firstname>Lori</firstname>
<lastname>Lemaris</lastname>
</record>
</records>
</xml>
<xml id="_ShowRecords">
<xsl:stylesheet
version="1.0"
xmlns:xsl="<xsl
aram name="sortKey" select="'firstname'"/>
<xsl
aram name="sortOrder" select="'ascending'"/>
<xsl:template match="/">
<xsl:apply-templates select="records"/>
</xsl:template>
<xsl:template match="records">
<div>
<xsl:apply-templates select="record">
<xsl:sort select="*[name(.)=$sortKey]|@*[name(.)=$sortKey]" order="{$sortOrder}"/>
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="record">
<div>(<xsl:value-of select="@id"/>) <xsl:value-of select="firstname"/><xsl:text> </xsl:text><xsl:value-of select="lastname"/></div>
</xsl:template>
</xsl:stylesheet>
</xml>
<xml id="_FilterRecords">
<xsl:stylesheet
version="1.0"
xmlns:xsl="<xsl
aram name="filterColumn" select="'firstname'"/>
<xsl
aram name="filterValue" select="'Daren'"/>
<xsl:template match="/">
<xsl:apply-templates select="records"/>
</xsl:template>
<xsl:template match="records">
<div>
<xsl:apply-templates select="record">
</xsl:apply-templates>
</div>
</xsl:template>
<!--
<xsl:template match="record[firstname='Daren']">
this one works, but it also displays all the other data without format,
only applies the format for the one that fits the match sentence
<xsl:template match="record['{$filterColumn}'='Daren']">
This one above this line, it just doesn't work at all
-->
<xsl:template match="record[$filterColumn=$filterValue]">
<div>(<xsl:value-of select="@id"/>) <xsl:value-of select="firstname"/><xsl:text> </xsl:text><xsl:value-of select="lastname"/>
</div>
</xsl:template>
</xsl:stylesheet>
</xml>
</body>
</html>
__________________
Edgar Sosa
Mexicali BC Mexico
I am using XML data Islands on IE 6.0, I want to apply the following XSLT to the XML.
by the way, the javascript functions are from an article written by Kurt Cagle, XML Pro
at this link
The following sentence works, but shows in the XSLT desired format only the one that fits in the criteria, and shows all the other ones like too ! only that in no format, just firstnames and lastname, no ID
<xsl:template match="record[firstname='Daren']">
I have stated 2 parameters wich are
<xsl
<xsl
I would like to use something like this, in order to later be able to pass any filter criteria
<xsl:template match="record[$filterColumn=$filterValue]">
but it just doesn't works, the browser gives me the following error
<b>Error: Variables may not be used within this expression</b>
And another thing, I would like that on the body onload event, I could call the function wich passes the parameters but with a Wildcard, so It would display all the records, currently I do this on body onload
<body onload="filterRecords('firstname','Daren')">
Is it possible to do something like
<body onload="filterRecords('firstname','*')">
first things first, here bellow I put the entire code, any help will be appreciated
<html>
<head>
<title>Sorting and Filtering Records</title>
</head>
<!--
<body onload="showRecords('id','ascending')">
-->
<body onload="filterRecords('firstname','Daren')">
<script language="Javascript">//<![CDATA[
function call(xslIsland,xmlIsland){
var xslDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
var rsltDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument"
var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate"
xslDoc.async = false;
rsltDoc.async = false;
xslDoc.load(xslIsland.XMLDocument);
xslTemplate.stylesheet=xslDoc;
var xslProc=xslTemplate.createProcessor();
xslProc.input=xmlIsland.XMLDocument;
xslProc.output=rsltDoc;
if (arguments.length >2 && arguments.length % 2 == 0){
for (var i=0;
i<Math.floor((arguments.length)/2)-1;
i++){
paramName=arguments[2*i+2];
paramValue=arguments[2*i+3];
xslProc.addParameter(paramName,paramValue);
}
}
xslProc.transform();
return rsltDoc;
}
function showRecords(sortKey,sortOrder){
var htmlDoc=
call(_ShowRecords,records,"sortKey", sortKey,"sortOrder",sortOrder);
window.container.innerHTML=htmlDoc.xml;
}
function filterRecords(filterColumn,filterValue){
var htmlDoc=
call(_FilterRecords,records,"filterColumn", filterColumn,"filterValue",filterValue);
window.container.innerHTML=htmlDoc.xml;
}
//]]></script>
Filters: <button onclick="filterRecords('firstname','Daren')">First Name = Daren</button><hr>
Sorting: <button onclick="showRecords('firstname',SortOrderList.value)">First Name</button>
<button onclick="showRecords('lastname',SortOrderList.value)">Last Name</button>
<button onclick= "showRecords('id',SortOrderList.value)">User ID</button>
<select name="SortOrderList" id="SortOrderList" value="ascending">
<option value="ascending" selected="selected">Ascending</option>
<option value="descending">Descending</option>
</select><hr>
<div id="container"></div>
<xml id="records">
<records>
<record id="101">
<firstname>Kurt</firstname>
<lastname>Cagle</lastname>
</record>
<record id="102">
<firstname>Aleria</firstname>
<lastname>Delamare</lastname>
</record>
<record id="103">
<firstname>Steven</firstname>
<lastname>Dallas</lastname>
</record>
<record id="104">
<firstname>Opus</firstname>
<lastname>Penguin</lastname>
</record>
<record id="105">
<firstname>Gina</firstname>
<lastname>Alacava</lastname>
</record>
<record id="106">
<firstname>Dean</firstname>
<lastname>Stanton</lastname>
</record>
<record id="107">
<firstname>Corey</firstname>
<lastname>Johnson</lastname>
</record>
<record id="108">
<firstname>Edgar</firstname>
<lastname>Marseiz</lastname>
</record>
<record id="109">
<firstname>Daren</firstname>
<lastname>Malecevitz</lastname>
</record>
<record id="110">
<firstname>Lori</firstname>
<lastname>Lemaris</lastname>
</record>
</records>
</xml>
<xml id="_ShowRecords">
<xsl:stylesheet
version="1.0"
xmlns:xsl="<xsl
<xsl
<xsl:template match="/">
<xsl:apply-templates select="records"/>
</xsl:template>
<xsl:template match="records">
<div>
<xsl:apply-templates select="record">
<xsl:sort select="*[name(.)=$sortKey]|@*[name(.)=$sortKey]" order="{$sortOrder}"/>
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="record">
<div>(<xsl:value-of select="@id"/>) <xsl:value-of select="firstname"/><xsl:text> </xsl:text><xsl:value-of select="lastname"/></div>
</xsl:template>
</xsl:stylesheet>
</xml>
<xml id="_FilterRecords">
<xsl:stylesheet
version="1.0"
xmlns:xsl="<xsl
<xsl
<xsl:template match="/">
<xsl:apply-templates select="records"/>
</xsl:template>
<xsl:template match="records">
<div>
<xsl:apply-templates select="record">
</xsl:apply-templates>
</div>
</xsl:template>
<!--
<xsl:template match="record[firstname='Daren']">
this one works, but it also displays all the other data without format,
only applies the format for the one that fits the match sentence
<xsl:template match="record['{$filterColumn}'='Daren']">
This one above this line, it just doesn't work at all
-->
<xsl:template match="record[$filterColumn=$filterValue]">
<div>(<xsl:value-of select="@id"/>) <xsl:value-of select="firstname"/><xsl:text> </xsl:text><xsl:value-of select="lastname"/>
</div>
</xsl:template>
</xsl:stylesheet>
</xml>
</body>
</html>
__________________
Edgar Sosa
Mexicali BC Mexico