Re: [xsl]Passing parameter to xsl stylesheet

Subject: Re: [xsl]Passing parameter to xsl stylesheet
From: "Antony Suryadinata" <antodinata@xxxxxxxxxxx>
Date: Thu, 30 Aug 2001 14:00:44 +1100
Re: [xsl]Passing parameter to xsl stylesheetHi Jim,

What I'm trying to do is pass in a nodeset into a stylesheet through a jsp page (running on Tomcat). In my jsp page, I do a query in
a database (Tamino in this case), get the nodeset that I need, load the stylesheet then I use the setParameter to set the parameter
in the stylesheet with the nodeset that I retrieved from the database. I am using XALAN as the XSLT parser. The reason I want to
pass in the nodeset not the URL is because when I try to pass in a URL with "[" (need that to query Tamino otherwise you get
everything in the database) in it, I got an error saying that the url has an invalid character.

My minimised stylesheet is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:ino="http://namespaces.softwareag.com/tamino/response2"; xmlns:xql="http://metalab.unc.edu/xql/";
xmlns:xalan="http://xml.apache.org/xalan"; exclude-result-prefixes="ino xql xalan">
 <xsl:output method="html" version="1.0"  indent="yes"/>

 <xsl:param name="Projects"/>

 <xsl:template match="ino:response">
  Project Lists: <br/>
  <xsl:for-each select="$Projects">
       <h2>*<xsl:value-of select="Name"/>*</h2>
    </xsl:for-each>
    <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

And my jsp code is:

    File xslFile = new File("stylesheet.xsl");
    Document xslDoc = docBuilder.parse(xslFile);
    DOMSource xslSource = new DOMSource(xslDoc);
    xslSource.setSystemId(xslFile.toString());

    Templates templates = tfactory.newTemplates(xslSource);
    Transformer transformer = templates.newTransformer();

    // query Tamino (tr)

        Document doc = docBuilder.parse(new InputSource(new StringReader(tr.toXmlString())));
        NodeSet nset = new NodeSet();
        nset.addNodes(doc.getElementsByTagName("xql:result"));

   // now set the parameter
       transformer.setParameter("Projects", nset);

     // query Tamino again for the XML source (xmlSource)
        transformer.transform(xmlSource, new StreamResult(out));


Thanks,

Antony

----- Original Message -----
From: cutlass
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Wednesday, August 29, 2001 6:40 PM
Subject: Re: [xsl]Passing parameter to xsl stylesheet


not quite sure what your question is;
yes params can be nodesets


the appropriate
http://www.dpawson.co.uk/xsl/sect2/N5982.html
and here is
http://aspn.activestate.com/ASPN/search?query=param&type=Archive_xsl-list
search of this list.
the method of passing of a parameter is dependant on your XSLT parser.
most command line methods will allow u to specifiy what params you are
passing and their values
for example if u use SAXON go here
http://saxon.sourceforge.net/saxon6.4.3/using-xsl.html
if u are performing transformations with MS Explorer with MSXML installed
look at this http://www.bayes.co.uk/xml/tutorial/atob/fromatob.xml
other software allows u to parse the param in the URL, but this is more of
added behavior to the actual webserver.
more information = i will try to answer your question.
cheers, jim fuller


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



_______________________________________
This Email has been scanned by MIMEsweeper
_______________________________________


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread