Creating Xpath Dynamically
Hi All,
I want to build the xpath expression dynamically in the xsl for for-each.
Scenario is like this::
1. From javascript I am sending the parameters to xsl.
2. In xsl I am taking those parameters
Now I want to use this parameters to build the xpath, but I might
get some of the values as null, so in that case I must eliminate
the null values.
And now the solution for this, is, dynamically building the
xpath expression for "for-each".
Following is my javascript::
function LoadProjects(){
var name= window.parent.importParamone.sortBy.value;
var xslProc;
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load("..//Repository//testNew.xml");
var xsl = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0" );
xsl.async = false;
xsl.load("loadData.xsl");
var template = new ActiveXObject("MSXML2.XSLTemplate");
template.stylesheet = xsl;
processor = template.createProcessor();
processor.input = xml;
processor.addParameter("sortBy", name);
processor.addParameter("filterNo", '12313'); processor.addParameter("filterName", '5.1'); processor.transform();
document.open();
document.write(processor.output);
document.close();
//document.write(xml.transformNode(xsl));
}
In the above we are sending filterNo and filterName to xsl
Now here is my xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslaram name="sortBy"/>
<xslaram name="filterNo"/>
<xslaram name="filterName"/>
<xslaram name="filterCondition"/>
<xsl:template match="/">
<html>
<head>
<link href="netAppsCss.css" rel="stylesheet" type="text/css" />
<link href="scroll_css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<xsl:for-each select="user/Employee[ProjectNumber=$filterNo]"> <xsl:sort select="*[name()=$sortBy]"/>
<tr>
<td class="tableData"><xsl:value-of select="ProjectNumber" /></td>
<td class="tableData"><xsl:value-of select="ProjectName"/></td>
<td class="tableData"><xsl:value-of select="TaskNumber" /></td>
<td class="tableData"><xsl:value-of select="TaskName" /></td>
<td class="tableData"><xsl:value-of select="Customer" /></td>
<td class="tableData"><xsl:value-of select="SoNumber" /></td>
<td class="tableData"><xsl:value-of select="SoLine" /></td>
<td class="tableData"><xsl:value-of select="TaskManager" /></td>
<td align="center" class="tableData" style="border-right:solid 1px #023183">
<input type="checkbox" name="checkbox" value="select" onclick="checkAlert(this)" /></td>
</tr>
</xsl:for-each>
</body>
</html>
</xsl:template></xsl:stylesheet>
and now in the above I am using only one filter condition, but when I
use multiple parameters like this.
<xsl:for-each select="user/Employee[ProjectNumber=$filterNo and ProjectNumber=$filterName]">
It is not working...................anyone please..................
|