Re: [xslt] Issues using parameters with namespaces
On Mon, Feb 28, 2022 at 2:01 PM George Joseph wrote: > > > On Mon, Feb 28, 2022 at 1:04 PM Nick Wellnhofer > wrote: > >> On 28/02/2022 20:54, George Joseph via xslt wrote: >> > 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. >> >> Right, the XPath engine uses both ->namespaces and ->nsHash. >> >> > 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. >> >> I meant that you should only use string or integer literals in parameter >> values and no other XPath expressions at all. This means to rework your >> stylesheets, of course. >> > > I think I'll stick with my solution to add the namespaces to the xpath > context. :) > Actually "//*[name()='dm:device']" works as well so maybe that's what I'll do. > Is there any reason why path parameters with namespaces haven't been > supported? > Would a pull request to add the namespaces in xsltNewTransformContext be > considered? > > > > >> >> Nick >> >> ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt
Re: [xslt] Issues using parameters with namespaces
On Mon, Feb 28, 2022 at 1:04 PM Nick Wellnhofer wrote: > On 28/02/2022 20:54, George Joseph via xslt wrote: > > 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. > > Right, the XPath engine uses both ->namespaces and ->nsHash. > > > 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. > > I meant that you should only use string or integer literals in parameter > values and no other XPath expressions at all. This means to rework your > stylesheets, of course. > I think I'll stick with my solution to add the namespaces to the xpath context. :) Is there any reason why path parameters with namespaces haven't been supported? Would a pull request to add the namespaces in xsltNewTransformContext be considered? > > Nick > > ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt
Re: [xslt] Issues using parameters with namespaces
On 28/02/2022 20:54, George Joseph via xslt wrote: 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. Right, the XPath engine uses both ->namespaces and ->nsHash. 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. I meant that you should only use string or integer literals in parameter values and no other XPath expressions at all. This means to rework your stylesheets, of course. Nick ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt
Re: [xslt] Issues using parameters with namespaces
On Mon, Feb 28, 2022 at 11:42 AM Nick Wellnhofer 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. > Okay. > > > 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 > ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt
Re: [xslt] Issues using parameters with namespaces
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. 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 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. Nick ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt
[xslt] Issues using parameters with namespaces
Greetings, I've been having a heck of a time trying to pass a parameter to xsltApplyStylesheet that has namespaces in the xpath expression. For example (abbreviated): stylesheet: xml: ... $ xsltproc --param path "//dm:device" pidf_lo.xslt pidf_lo_test.xml XPath error : Undefined namespace prefix runtime error Evaluating user parameter path failed if I hard code that select="//dm:device" it works fine. 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 would have thought this would have been done automatically though. Did I miss something or is there a better way to do this? Thanks! -- George Joseph Asterisk Software Developer Check us out at www.sangoma.com and www.asterisk.org [image: image.png] ___ xslt mailing list, project page http://xmlsoft.org/XSLT/ xslt@gnome.org https://mail.gnome.org/mailman/listinfo/xslt