Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2007, 03:49 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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..................


 
Old February 20th, 2007, 08:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT has no capability to build an XPath expression dynamically. Some processors have extensions, for example saxon:evaluate(), that are designed to fill this gap. There's a function defined in EXSLT (www.exslt.org) called dyn:evaluate() - check whether there is an implementation for your chosen processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 20th, 2007, 08:30 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.for your suggestion i did in different way by using <xsl:if>

here is the code

<xsl:for-each select="user/Employee">
      <xsl:sort select="*[name()=$sortBy]"/>
      <xsl:if test="contains(ProjectNumber,$ProjNo)">
      <xsl:if test="contains(ProjectName,$ProjName)">
      <xsl:if test="contains(TaskNumber,$TaskNo)">
      <xsl:if test="contains(TaskName,$TaskNme)">
      <xsl:if test="contains(Customer,$Cust)">
      <xsl:if test="contains(SoNumber,$SoNum)">
      <xsl:if test="contains(TaskManager,$TaskMgr)">
      <tr>
        <td style="display:none"><xsl:value-of select="Sunday" /></td>
        <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:if>
      </xsl:if>
      </xsl:if>
      </xsl:if>
      </xsl:if>
      </xsl:if>
      </xsl:if>
      </xsl:for-each>

i know this is not the proper solution by it solved my purpose


any way Thank you Michael Kay









Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically creating TemplateField.... aekta ASP.NET 2.0 Professional 1 March 19th, 2007 02:26 PM
Creating Conrols dynamically jamil umar ASP.NET 1.0 and 1.1 Basics 3 February 13th, 2006 01:02 PM
Creating Columns Dynamically?? cbeasle1 Crystal Reports 2 June 10th, 2005 09:15 AM
Creating controls dynamically Renu ASP.NET 1.0 and 1.1 Basics 9 December 19th, 2004 10:21 AM
Dynamically creating an array youngj PHP How-To 0 November 8th, 2004 03:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.