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.i mportParamone.s ortBy.value;
var xslProc;
var xml = new ActiveXObject(" Microsoft.XMLDO M");
xml.async = false;
xml.load("..//Repository//testNew.xml");
var xsl = new ActiveXObject(" MSXML2.FreeThre adedDomDocument .3.0");
xsl.async = false;
xsl.load("loadD ata.xsl");
var template = new ActiveXObject(" MSXML2.XSLTempl ate");
template.styles heet = xsl;
processor = template.create Processor();
processor.input = xml;
processor.addPa rameter("sortBy ", name);
processor.addPa rameter("filter No", '12313'); processor.addPa rameter("filter Name", '5.1'); processor.trans form();
document.open() ;
document.write( processor.outpu t);
document.close( );
//document.write( xml.transformNo de(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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:param name="sortBy"/>
<xsl:param name="filterNo"/>
<xsl:param name="filterNam e"/>
<xsl:param name="filterCon dition"/>
<xsl:template match="/">
<html>
<head>
<link href="netAppsCs s.css" rel="stylesheet " type="text/css" />
<link href="scroll_cs s.css" rel="stylesheet " type="text/css" />
</head>
<body>
<xsl:for-each select="user/Employee[ProjectNumber=$ filterNo]"> <xsl:sort select="*[name()=$sortBy]"/>
<tr>
<td class="tableDat a"><xsl:valu e-of select="Project Number" /></td>
<td class="tableDat a"><xsl:valu e-of select="Project Name"/></td>
<td class="tableDat a"><xsl:valu e-of select="TaskNum ber" /></td>
<td class="tableDat a"><xsl:valu e-of select="TaskNam e" /></td>
<td class="tableDat a"><xsl:valu e-of select="Custome r" /></td>
<td class="tableDat a"><xsl:valu e-of select="SoNumbe r" /></td>
<td class="tableDat a"><xsl:valu e-of select="SoLine" /></td>
<td class="tableDat a"><xsl:valu e-of select="TaskMan ager" /></td>
<td align="center" class="tableDat a" style="border-right:solid 1px #023183">
<input type="checkbox" name="checkbox" value="select" onclick="checkA lert(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........ ...........anyo ne please......... .........
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.i mportParamone.s ortBy.value;
var xslProc;
var xml = new ActiveXObject(" Microsoft.XMLDO M");
xml.async = false;
xml.load("..//Repository//testNew.xml");
var xsl = new ActiveXObject(" MSXML2.FreeThre adedDomDocument .3.0");
xsl.async = false;
xsl.load("loadD ata.xsl");
var template = new ActiveXObject(" MSXML2.XSLTempl ate");
template.styles heet = xsl;
processor = template.create Processor();
processor.input = xml;
processor.addPa rameter("sortBy ", name);
processor.addPa rameter("filter No", '12313'); processor.addPa rameter("filter Name", '5.1'); processor.trans form();
document.open() ;
document.write( processor.outpu t);
document.close( );
//document.write( xml.transformNo de(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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:param name="sortBy"/>
<xsl:param name="filterNo"/>
<xsl:param name="filterNam e"/>
<xsl:param name="filterCon dition"/>
<xsl:template match="/">
<html>
<head>
<link href="netAppsCs s.css" rel="stylesheet " type="text/css" />
<link href="scroll_cs s.css" rel="stylesheet " type="text/css" />
</head>
<body>
<xsl:for-each select="user/Employee[ProjectNumber=$ filterNo]"> <xsl:sort select="*[name()=$sortBy]"/>
<tr>
<td class="tableDat a"><xsl:valu e-of select="Project Number" /></td>
<td class="tableDat a"><xsl:valu e-of select="Project Name"/></td>
<td class="tableDat a"><xsl:valu e-of select="TaskNum ber" /></td>
<td class="tableDat a"><xsl:valu e-of select="TaskNam e" /></td>
<td class="tableDat a"><xsl:valu e-of select="Custome r" /></td>
<td class="tableDat a"><xsl:valu e-of select="SoNumbe r" /></td>
<td class="tableDat a"><xsl:valu e-of select="SoLine" /></td>
<td class="tableDat a"><xsl:valu e-of select="TaskMan ager" /></td>
<td align="center" class="tableDat a" style="border-right:solid 1px #023183">
<input type="checkbox" name="checkbox" value="select" onclick="checkA lert(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........ ...........anyo ne please......... .........
Comment