Re: [xslt] Issues using parameters with namespaces




On Mon, Feb 28, 2022 at 11:42 AM Nick Wellnhofer <wellnhofer aevum de> wrote:
On 28/02/2022 18:50, George Joseph via xslt wrote:
> I've been having a heck of a time trying to pass a parameter
> to xsltApplyStylesheet
> that has namespaces in the xpath _expression_.

This use case is simply not supported.

Okaaaaay.
 

> Finally I did find a workaround by calling xsltNewTransformContext() then
> iterating
> over the nsDefs in the stylesheet document and calling xmlXPathRegisterNs on
> ctxt->xpathCtxt for each nsDef.

I'm a bit puzzled that this worked at all. See the code here:


https://gitlab.gnome.org/GNOME/libxslt/-/blob/master/libxslt/variables.c#L1581

 I think it works because xsltProcessUserParamInternal only sets
xpctxt->namespaces = NULL but it doesn't clear xpctxt->nsHash which is where
xmlXPathRegisterNs puts the namespaces to be registered.


But the _expression_ is compiled before resetting the namespaces, so I guess
that's why.

> I would have thought this would have been done automatically though.  Did I
> miss something or is there a better way to do this?

No, I'd recommend that you only use string and integer params.

Can you give me a hint?   I've had absolutely no luck is trying to pass a path
as a string and getting it to result in something other than "The 'select' _expression_
did not evaluate to a node set" even in an absurdly simple example.  I'm passing
the path double quoted "'/dm:device'" and have tried various combinations of
"select=" and "with-param".    Even Google is failing me so any help would be appreciated.

Thanks!

 

Nick


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]