473,782 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

supplying runtime parameter

sp
the xml file i used
<catalog>
<cd>
<title year="1990">Emp ire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd>
<title year="1995">Hid e your heart</title>
<artist>Bonni e Tyler</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Gre atest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Sti ll got the blues</title>
<artist>Gary Moore</artist>
<price>10.20</price>
</cd>
<cd>
<title year="1998">Ero s</title>
<artist>Eros Ramazzotti</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1998">One night only</title>
<artist>Bee Gees</artist>
<price>10.90</price>
</cd>
</catalog>
the output expected
<cd>
<title year="1990">Emp ire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
the xsl used
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/">
<xsl:for-each select="/catalog/cd[title[@year='1990']]">
<catalog>
<xsl:copy-of select="." />
</catalog>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

in the above xsl i am filtering the xml by hardcoding the value of year
is there any way to pass the filtering parameter as a runtime argument
( i am working in C++ )

by using the transformNode function i am abel to apply the filtering in
XSL but how can i pass the filter parameter runtime

could anyone help in this issue

thanks
praveen

Jan 25 '06 #1
3 1734


sp wrote:
<xsl:for-each select="/catalog/cd[title[@year='1990']]"> in the above xsl i am filtering the xml by hardcoding the value of year
is there any way to pass the filtering parameter as a runtime argument
Yes, your stylesheet can declare a global parameter
<xsl:param name="inputYear " />
then you need to check the API documentation of your XSLT processor on
how to set that parameter before running a transformation e.g. there
will a method alike
xsltProcessor.a ddParameter('in putYear', '2000')
( i am working in C++ )

by using the transformNode function i am abel to apply the filtering in
XSL but how can i pass the filter parameter runtime


Which processor are you using, some version of Microsoft MSXML?
API docs are here:
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/xmlsdk/html/9ddcd728-2646-494a-8fa4-3b68e8c032b7.as p>
Note however that your example does not need a stylesheet at all, a
simple XPath expression evaluation (e.g. selectNodes, selectSingleNod e
with MSXML) would give you the result as you do not seem to want to
create any nodes, you simple select one cd element and that can be done
with pure XPath without using XSLT e.g.:
xmlDocument.set Property('Selec tionLanguage', 'XPath');
var someInputYear = '2000';
var cdElement = xmlDocument.sel ectSingleNode(
'/catalog/cd[title[@year = "' + someInputYear + '"]]');

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 25 '06 #2
This you might find this java utility class helpful ....
I use it to dynamically add a xsl:variable to an xsl transform.
package acme.com;

import java.io.ByteArr ayInputStream;
import java.io.IOExcep tion;
import java.io.InputSt ream;
import java.util.Itera tor;
import java.util.Map;

import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.parse rs.FactoryConfi gurationError;
import javax.xml.parse rs.ParserConfig urationExceptio n;

import org.apache.comm ons.logging.Log ;
import org.apache.comm ons.logging.Log Factory;
import org.w3c.dom.Att r;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Nam edNodeMap;
import org.w3c.dom.Nod e;
import org.w3c.dom.Tex t;
import org.xml.sax.SAX Exception;

public class XSLUtils {
public static InputStream addParameters(I nputStream xsl, Map
parameters) {
Document document = null;
try {
document =
DocumentBuilder Factory.newInst ance().newDocum entBuilder().pa rse(xsl);

Node root = document.getDoc umentElement();

Iterator iterator = parameters.keyS et().iterator() ;
while(iterator != null && iterator.hasNex t()) {
String name = (String)iterato r.next();
String value = (String)paramet ers.get(name);

Node element = document.create Element("xsl:va riable");
NamedNodeMap attributes = element.getAttr ibutes();
Attr nameAttr = document.create Attribute("name ");
nameAttr.setNod eValue(name);
attributes.setN amedItem(nameAt tr);

Text textNode = document.create TextNode(value) ;
element.appendC hild(textNode);

root.insertBefo re(element, root.getFirstCh ild());
}

// now convert document to an InputStream
return new
ByteArrayInputS tream(XMLTransf ormer.transform (document,
false).getBytes ());
} catch(SAXExcept ion e) {
LOG.error(e);
} catch(IOExcepti on e) {
LOG.error(e);
} catch(ParserCon figurationExcep tion e) {
LOG.error(e);
} catch(FactoryCo nfigurationErro r e) {
LOG.error(e);
} catch(XMLTransf ormException e) {
LOG.error(e);
} finally {
StreamUtils.clo se(xsl);
}

return null;
}
}

Then to use it ...

StringBuffer sb = new StringBuffer();
sb.append("<?xm l version=\"1.0\"
encoding=\"UTF-8\"?>");
sb.append(xml.g enerateXml()); // result of
xml.generateXml () is a string of XML
xmlStream = new
ByteArrayInputS tream(sb.toStri ng().getBytes(" UTF-8"));

InputStream xslStream =
getServletConte xt().getResourc eAsStream("/WEB-INF/xsl/joborder-email-template.xsl");
xslStream = XSLUtils.addPar ameters(xslStre am, params); //
xsl:variables added here.

// apply transform to XML to generate HTML
String html = DoWhatYouHaveTo To.transform(xm lStream, xslStream);

// add xsl variable assignments
xslStream = XSLUtils.addPar ameters(xslStre am, params);

// apply transform to XML to generate HTML
String html = XSLTransformer. transform(xmlSt ream,
xslStream);

Jan 26 '06 #3
hi,

you could use RefleX for this purpose :
http://reflex.gforge.inria.fr/

a very simple script can be done like this :

<?xml version="1.0" encoding="iso-8859-1"?>
<xcl:active-sheet xmlns:xcl="http ://www.inria.fr/xml/active-tags/xcl">
<xcl:transfor m output="/path/to/file.html"
source="/path/to/file.xml" stylesheet="/path/to/stylesheet.xsl" >
<xcl:param name="inputYear " value="1990"/>
</xcl:transform>
</xcl:active-sheet>

inside your stylesheet, just declare the parameter :
<xsl:param name="inputYear "/>
and change the hard-coded value where expected :
<xsl:for-each select="/catalog/cd[title[@year=$inputYea r]]">

notice that for this example, you don't need a stylesheet, you can get
directly the output like this :
<?xml version="1.0" encoding="iso-8859-1"?>
<xcl:active-sheet xmlns:xcl="http ://www.inria.fr/xml/active-tags/xcl">
<xcl:parse name="myCatalog " source="/path/to/file.xml"/>
<xcl:transfor m output="/path/to/file.html" source="{
$myCatalog/catalog/cd[title/@year = '1990'] }"/>
</xcl:active-sheet>

the difference is that there is no stylesheet specified, so it is a
simple copy of the node selected

notice that such scripts could be launched in batch mode as well as in
Web application, and you can of course pass parameters from the
environment (batch) or from the URL query string (HTTP)

have a look at the RefleX web site

sp wrote:
the xml file i used
<catalog>
<cd>
<title year="1990">Emp ire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd>
<title year="1995">Hid e your heart</title>
<artist>Bonni e Tyler</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Gre atest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Sti ll got the blues</title>
<artist>Gary Moore</artist>
<price>10.20</price>
</cd>
<cd>
<title year="1998">Ero s</title>
<artist>Eros Ramazzotti</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1998">One night only</title>
<artist>Bee Gees</artist>
<price>10.90</price>
</cd>
</catalog>
the output expected
<cd>
<title year="1990">Emp ire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
the xsl used
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/">
<xsl:for-each select="/catalog/cd[title[@year='1990']]">
<catalog>
<xsl:copy-of select="." />
</catalog>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

in the above xsl i am filtering the xml by hardcoding the value of year
is there any way to pass the filtering parameter as a runtime argument
( i am working in C++ )

by using the transformNode function i am abel to apply the filtering in
XSL but how can i pass the filter parameter runtime

could anyone help in this issue

thanks
praveen

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Jan 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1673
by: Raj | last post by:
hi, How to pass a Two Date parameter to a report at runtime using VB .NET 1. How do we pass multiple values eg. Startdate, EndDate to crystal reports parameter. 2. I have a report to filter by two dates like FromDate And ToDate
8
5970
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
1
6400
by: Bill Nguyen | last post by:
Report source is an SQLSERVER 2K store procedure. VB.NET application. Report created by CR 8.5. At runtime, I still had to click "CANCEL" to bypass the parameter prompts before the report display correctly. Also, print option grayed out although it was available at design time. Thanks a million! Bill
12
5797
by: leaf | last post by:
Hi, How to call function at runtime, based on a struct that contains the information for the function call: struct func_to_call { int function_id; // function id to call unsigned int nparams; // number of parameters unsigned long* parameter; // the parameter(s) to pass }
3
11589
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the content I want to execute based on the name of the asp:Content control. As shown in the code snippet below, to get the content I want to display, I call the GetContentPagePath public method in PageRenderer passing a string duplicating the value...
2
4040
by: Arif Khan | last post by:
Hi, I want to write down a function entry point logging method, allowing logging of passed in parameters values along with function name and parameter names. I know I can get the parameter name and function name using System.Reflection or StackFrame but not sure if if it's possible to retreive runtime passed in actual parameter values in .net 1.1 ? e.g. class User { public string GetName(int userId)
2
12802
by: planetthoughtful | last post by:
Hi All, I have an ASP.NET page that displays a GridView control based on an ObjectDataSource control. I'm wondering if it's possible to base the ObjectDataSource in question on a parameter query, with the ability to set the parameter value at run time (in the Page_Load event, perhaps?)? Basically, I'd like to display records in the GridView based on values
18
4359
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
3
2518
by: =?Utf-8?B?R3JhaGFt?= | last post by:
I've added 2 tracking services to the wf runtime; one is the standard SqlTrackingService: trackingService = new SqlTrackingService(<trackingConnectionString>); <workflow Runtime>.AddService(trackingService); trackingService.IsTransactional = false; trackingService.UseDefaultProfile = true; This works just fine.
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.