Search code examples
javaxsltsaxontransformer-model

Providing parameters to XSLT program using Java API


What I want to do is:

setParameter(String name, String value)

But the API is:

void setParameter(QName name, XdmValue value)

I can't find any example to properly create XdmValue and QName, examples I found are all using different versions of this function/api.


Solution

  • Very often parameters have names that are in no namespace, so you can construct the QName using the constructor new QName("p"). If the parameter value is a string, you can construct the value using new XdmAtomicValue("value"). So your example reduces to

    setParameter(new QName(name), new XdmAtomicValue(value))
    

    In designing an API like this, one has to judge carefully how to balance the simplicity that comes from providing "shortcut" methods for common simple cases, versus the complexity that comes from having zillions of methods. So I provided new QName(string), but I didn't provide setParameter(string, string).