2

I am using Saxon 9 HE and in NetBeans 7.0.1, I get the following error when I try to send a parameter to my stylesheet:

enter image description here

Just to make sure, is that the good way to send a parameter so I can get it back with

<xsl:param ... /> ?

If so, how can I use it?

Thank you!

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
Cybrix
  • 3,248
  • 5
  • 42
  • 61

2 Answers2

3

See S9APIExamples.java :

String[] fruit = {"apple", "banana", "cherry"};
QName paramName = new QName("in");
for (String s: fruit) {
    StringWriter sw = new StringWriter();
    out.setOutputWriter(sw);
    t.setParameter(paramName, new XdmAtomicValue(s));
    t.setDestination(out);
    t.transform();
    System.out.println(s + ": " + sw.toString());
}
MK.
  • 33,605
  • 18
  • 74
  • 111
1

From the message it seems quite obvious that you need to pass an net.sf.saxon.s9api.Qname as the first argument (not just the string "myVar").

And the second argument must be constructed as an net.sf.saxon.s9api.XdmValue.

Just to make sure, is that the good way to send a parameter so I can get it back with

<xsl:param ... /> ?

In your XSLT stylesheets (the primary one and any stylesheet module that is referenced in an xsl:import or an xsl:include directive) you must have a global (child of xsl:stylesheet) xsl:param with the same name as the string used to construct the Qname that you are passing as the first argument to setParameter().

When the setParameter() method is executed and then the transformation is invoked, the corresponding global xsl:param will have the value that was used to construct the XdmValue passed as the second argument to setParameter().

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • Thank you. But I find that too complicated or not very related to what I am trying to do. Is that really the way to send a parameter to the `XSLT Stylesheet`? – Cybrix Jan 22 '12 at 05:02
  • I am not sure why you are expecting a less "complicated" way to specify and pass external parameters. A parameter name can be any QName (name and namespace-uri) and the value of the parameter can be of any XDM type. An API method to specify this data cannot be "simpler" than the one Saxon provides. Are you sure you know what you want to do? If it is different than what the `setParameter()` method does, then you have to edit the question and to describe in detail what you want to do. There is a simpler method for passing just string values and this is done on the command-line invoking Saxon. – Dimitre Novatchev Jan 22 '12 at 05:18