Re: Issues using parameters with namespaces
George Joseph via xslt <[email protected]> Mon, 28 Feb 2022 12:54:17 -0700
| Newsgroups | gmane.comp.gnome.lib.xslt |
|---|---|
| Message-ID | <CAP=uFEudkfXuJDQFaFdaNQ6MV2sv_-=4qJcKzbtL193GEwdsHg@mail.gmail.com> |
--===============1246322425615506185== Content-Type: multipart/alternative; boundary="000000000000d129c605d9196a93" --000000000000d129c605d9196a93 Content-Type: text/plain; charset="UTF-8" On Mon, Feb 28, 2022 at 11:42 AM Nick Wellnhofer <[email protected]> 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 > --000000000000d129c605d9196a93 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><div class=3D"gmail_quote"><div= dir=3D"ltr" class=3D"gmail_attr">On Mon, Feb 28, 2022 at 11:42 AM Nick Wel= lnhofer <<a href=3D"mailto:[email protected]" target=3D"_blank">wellnh= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" sty= le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi= ng-left:1ex">On 28/02/2022 18:50, George Joseph via xslt wrote:<br> > I've been having a heck of a time trying to pass a parameter <br> > to=C2=A0xsltApplyStylesheet<br> > that has namespaces in the xpath expression.<br> <br> This use case is simply not supported.<br></blockquote><div><br></div><div>= Okaaaaay.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"= margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef= t:1ex"> <br> > Finally I did find a workaround by calling=C2=A0xsltNewTransformContex= t() then <br> > iterating<br> > over the nsDefs in the stylesheet document and calling=C2=A0xmlXPathRe= gisterNs on<br> > ctxt->xpathCtxt for each nsDef.<br> <br> I'm a bit puzzled that this worked at all. See the code here:<br> <br> <br> <a href=3D"https://gitlab.gnome.org/GNOME/libxslt/-/blob/master/libxslt/var= iables.c#L1581" rel=3D"noreferrer" target=3D"_blank">https://gitlab.gnome.o= rg/GNOME/libxslt/-/blob/master/libxslt/variables.c#L1581</a></blockquote><d= iv><br></div><div>=C2=A0I think it works because=C2=A0xsltProcessUserParamI= nternal only sets</div><div><span>xpctxt</span><span>-></span><span>name= spaces =3D NULL but it doesn't clear xpctxt->nsHash which is where</= span></div><div><span>xmlXPathRegisterNs puts the namespaces to be register= ed.<br></span></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0= px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br> <br> But the expression is compiled before resetting the namespaces, so I guess = <br> that's why.<br> <br> > I would have thought this would have been done automatically though.= =C2=A0 Did I<br> > miss something or is there a better way to do this?<br> <br> No, I'd recommend that you only use string and integer params.<br></blo= ckquote><div><br></div><div>Can you give me a hint?=C2=A0 =C2=A0I've ha= d absolutely no luck is trying to pass a path</div><div>as a string and get= ting it to result in something other than "The 'select' expres= sion</div><div>did not evaluate to a node set" even in an absurdly=C2= =A0simple example.=C2=A0 I'm passing</div><div>the path double quoted &= quot;'/dm:device'" and have tried various combinations of</div= ><div>"select=3D" and "with-param".=C2=A0 =C2=A0 Even G= oogle is failing me so any help would be appreciated.</div><div><br></div><= div>Thanks!</div><div><br></div><div>=C2=A0</div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex"> <br> Nick<br> </blockquote></div></div> --000000000000d129c605d9196a93-- --===============1246322425615506185== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ xslt mailing list, project page http://xmlsoft.org/XSLT/ [email protected] https://mail.gnome.org/mailman/listinfo/xslt --===============1246322425615506185==--