Re: XdmValue objects returned from applyTemplates()

Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]> Wed, 4 Aug 2021 23:40:19 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
--===============0913596590880576117==
Content-Type: multipart/alternative;
	boundary="_5B4FC50C-2DF7-4BCF-B842-E7FB35EE50BA_"

--_5B4FC50C-2DF7-4BCF-B842-E7FB35EE50BA_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

Depends a bit what you mean by =E2=80=9CJSON-oriented=E2=80=9D. Maps and ar=
rays can of course contain XDM nodes in their values (and I don=E2=80=99t t=
hink we always check that these belong to the right Configuration when supp=
lied via external APIs, in the same way that we check for nodes). Writing c=
ode that converts a map-containing-nodes from one Configuration to a map-co=
ntaining-equivalent-nodes from a different Configuration would be a pretty =
substantial undertaking.

Sender.send() expects a Source object, and the JAXP Source interface is ver=
y XML-biased.

Michael Kay
Saxonica

From: Alan Painter
Sent: 04 August 2021 22:33
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] XdmValue objects returned from applyTemplates()

I see that I was too hasty in saying that it was "working" for me.

I'd like the XdmValue to be any arbitrary Xdm with un-annotated XML, maps, =
arrays and atomics (no need for functions).=C2=A0=C2=A0
But maps and and arrays cannot be cast to NodeInfo (or, at least, I'm getti=
ng an error when doing this).

Would there be a way to send JSON-oriented XdmValue to Sender.send()?=C2=A0=
=C2=A0
(I'm thinking that a pure JSON XdmValue wouldn't need to have its NamePool =
converted, but what about a mix of XML and maps/arrays?)

thanks again for any help



On Wed, Aug 4, 2021 at 10:12 PM Alan Painter <[email protected]> wrote=
:
I'm finally getting around to implementing something w.r.t. the pointers th=
at you gave me, Michael.

My objective is to convert a given XdmValue so that it can become the input=
 for a Xslt30Transformer=C2=A0with a different NamePool from the origin Xsl=
t30Transformer.

This seems to be working for me.=C2=A0 I'm curious if this is OK and if the=
re isn't a shorter way.

private XdmValue convertXdmValueForXslt(final XdmValue toConvert, final Xsl=
t30Transformer destinationXslt) throws XPathException {
    final RawDestination        rawDest  =3D new RawDestination();
    final PipelineConfiguration pipe     =3D destinationXslt.getUnderlyingC=
ontroller().makePipelineConfiguration();
    final Receiver              receiver =3D rawDest.getReceiver(pipe, null=
);

    Sender.send((NodeInfo) toConvert.getUnderlyingValue(), receiver, new Pa=
rseOptions());

    return rawDest.getXdmValue();
}

Thanks again for the help

best regards

-alan

On Thu, Jul 15, 2021 at 1:18 AM Michael Kay <[email protected]> wrote:
>I'm wondering what the drawbacks would be for re-using a same Processor by=
 a (potentially) large number of Xslt30Transformers in parallel.=20

For most cases, none.

Potentially you could hit limits on the number of names allowed in a NamePo=
ol. In practice we never see people hitting those limits.

Slightly more likely is that you hit a problem that the schema components h=
eld by a Processor must be consistent (for example, you can't have two diff=
erent types with the same name - which could happen if you want to use two =
different versions of the same schema).

In general, you should only create a single Processor unless you have clear=
 reasons to do otherwise.

There is in fact a low-level mechanism to copy an XdmNode owned by one Proc=
essor to a different Processor: it's the NamePoolConverter class, used by t=
he method Sender.sendDocumentInfo(). But it's not exposed in a convenient w=
ay at the s9api interface.

Michael Kay
Saxonica




_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help=20


--_5B4FC50C-2DF7-4BCF-B842-E7FB35EE50BA_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta ht=
tp-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta name=
=3DGenerator content=3D"Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Menlo;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0cm;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:"Courier New";}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style></head><body lang=3DEN-GB link=3Dblue vlink=3D"#954F72" style=3D=
'word-wrap:break-word'><div class=3DWordSection1><p class=3DMsoNormal>Depen=
ds a bit what you mean by =E2=80=9CJSON-oriented=E2=80=9D. Maps and arrays =
can of course contain XDM nodes in their values (and I don=E2=80=99t think =
we always check that these belong to the right Configuration when supplied =
via external APIs, in the same way that we check for nodes). Writing code t=
hat converts a map-containing-nodes from one Configuration to a map-contain=
ing-equivalent-nodes from a different Configuration would be a pretty subst=
antial undertaking.</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=
=3DMsoNormal>Sender.send() expects a Source object, and the JAXP Source int=
erface is very XML-biased.</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal>Michael Kay</p><p class=3DMsoNormal>Saxonica</p><p class=
=3DMsoNormal><o:p>&nbsp;</o:p></p><div style=3D'mso-element:para-border-div=
;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p c=
lass=3DMsoNormal style=3D'border:none;padding:0cm'><b>From: </b><a href=3D"=
mailto:[email protected]">Alan Painter</a><br><b>Sent: </b>04 August 2=
021 22:33<br><b>To: </b><a href=3D"mailto:[email protected]"=
>Mailing list for the SAXON XSLT and XQuery processor</a><br><b>Subject: </=
b>Re: [saxon] XdmValue objects returned from applyTemplates()</p></div><p c=
lass=3DMsoNormal><o:p>&nbsp;</o:p></p><div><p class=3DMsoNormal>I see that =
I was too hasty in saying that it was &quot;working&quot; for me.</p><div><=
p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>I'=
d like the XdmValue to be any arbitrary Xdm with un-annotated XML, maps, ar=
rays and atomics (no need for functions).&nbsp;&nbsp;</p></div><div><p clas=
s=3DMsoNormal>But maps and and arrays cannot be cast to NodeInfo (or, at le=
ast, I'm getting an error when doing this).</p></div><div><p class=3DMsoNor=
mal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>Would there be a w=
ay to send JSON-oriented XdmValue to Sender.send()?&nbsp;&nbsp;</p></div><d=
iv><p class=3DMsoNormal>(I'm thinking that a pure JSON XdmValue wouldn't ne=
ed to have its NamePool converted, but what about a mix of XML and maps/arr=
ays?)</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p=
 class=3DMsoNormal>thanks again for any help</p></div><div><p class=3DMsoNo=
rmal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p>=
</p></div></div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div><div><p clas=
s=3DMsoNormal>On Wed, Aug 4, 2021 at 10:12 PM Alan Painter &lt;<a href=3D"m=
ailto:[email protected]">[email protected]</a>&gt; wrote:</p></di=
v><blockquote style=3D'border:none;border-left:solid #CCCCCC 1.0pt;padding:=
0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><div><p class=3DMsoNo=
rmal>I'm finally getting around to implementing something w.r.t. the pointe=
rs that you gave me, Michael.</p><div><p class=3DMsoNormal><o:p>&nbsp;</o:p=
></p></div><div><p class=3DMsoNormal>My objective is to convert a given Xdm=
Value so that it can become the input for a Xslt30Transformer&nbsp;with a d=
ifferent NamePool from the origin Xslt30Transformer.</p></div><div><p class=
=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>This seem=
s to be working for me.&nbsp; I'm curious if this is OK and if there isn't =
a shorter way.</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></di=
v><div><pre><b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;col=
or:navy'>private </span></b><span style=3D'font-size:9.0pt;font-family:"Men=
lo",serif;color:black'>XdmValue convertXdmValueForXslt(</span><b><span styl=
e=3D'font-size:9.0pt;font-family:"Menlo",serif;color:navy'>final </span></b=
><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:black'>XdmV=
alue toConvert, </span><b><span style=3D'font-size:9.0pt;font-family:"Menlo=
",serif;color:navy'>final </span></b><span style=3D'font-size:9.0pt;font-fa=
mily:"Menlo",serif;color:black'>Xslt30Transformer destinationXslt) </span><=
b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:navy'>thro=
ws </span></b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;colo=
r:black'>XPathException {<br>=C2=A0=C2=A0=C2=A0 </span><b><span style=3D'fo=
nt-size:9.0pt;font-family:"Menlo",serif;color:navy'>final </span></b><span =
style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:black'>RawDestinat=
ion=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rawDest=C2=A0 =3D </span><b><=
span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:navy'>new </s=
pan></b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:blac=
k'>RawDestination();<br>=C2=A0=C2=A0=C2=A0 </span><b><span style=3D'font-si=
ze:9.0pt;font-family:"Menlo",serif;color:navy'>final </span></b><span style=
=3D'font-size:9.0pt;font-family:"Menlo",serif;color:black'>PipelineConfigur=
ation pipe=C2=A0=C2=A0=C2=A0=C2=A0 =3D destinationXslt.getUnderlyingControl=
ler().makePipelineConfiguration();<br>=C2=A0=C2=A0=C2=A0 </span><b><span st=
yle=3D'font-size:9.0pt;font-family:"Menlo",serif;color:navy'>final </span><=
/b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:black'>Re=
ceiver=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0receiver =3D rawDest.getReceiver(pipe, </span><b><span style=3D=
'font-size:9.0pt;font-family:"Menlo",serif;color:navy'>null</span></b><span=
 style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:black'>);<br><br>=
=C2=A0=C2=A0=C2=A0 Sender.<i>send</i>((NodeInfo) toConvert.getUnderlyingVal=
ue(), receiver, </span><b><span style=3D'font-size:9.0pt;font-family:"Menlo=
",serif;color:navy'>new </span></b><span style=3D'font-size:9.0pt;font-fami=
ly:"Menlo",serif;color:black'>ParseOptions());<br><br>=C2=A0=C2=A0=C2=A0 </=
span><b><span style=3D'font-size:9.0pt;font-family:"Menlo",serif;color:navy=
'>return </span></b><span style=3D'font-size:9.0pt;font-family:"Menlo",seri=
f;color:black'>rawDest.getXdmValue();<br>}<o:p></o:p></span></pre></div><di=
v><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal=
>Thanks again for the help</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</=
o:p></p></div><div><p class=3DMsoNormal>best regards</p></div><div><p class=
=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>-alan</p>=
</div></div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div><div><p class=3D=
MsoNormal>On Thu, Jul 15, 2021 at 1:18 AM Michael Kay &lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank">[email protected]</a>&gt; w=
rote:</p></div></div></blockquote></div><p class=3DMsoNormal style=3D'margi=
n-left:9.6pt'>&gt;I'm wondering what the drawbacks would be for re-using a =
same Processor by a (potentially) large number of Xslt30Transformers in par=
allel. <br><br>For most cases, none.<br><br>Potentially you could hit limit=
s on the number of names allowed in a NamePool. In practice we never see pe=
ople hitting those limits.<br><br>Slightly more likely is that you hit a pr=
oblem that the schema components held by a Processor must be consistent (fo=
r example, you can't have two different types with the same name - which co=
uld happen if you want to use two different versions of the same schema).<b=
r><br>In general, you should only create a single Processor unless you have=
 clear reasons to do otherwise.<br><br>There is in fact a low-level mechani=
sm to copy an XdmNode owned by one Processor to a different Processor: it's=
 the NamePoolConverter class, used by the method Sender.sendDocumentInfo().=
 But it's not exposed in a convenient way at the s9api interface.<br><br>Mi=
chael Kay<br>Saxonica<br><br><br><br><br>__________________________________=
_____________<br>saxon-help mailing list archived at <a href=3D"http://saxo=
n.markmail.org/" target=3D"_blank">http://saxon.markmail.org/</a><br><a hre=
f=3D"mailto:[email protected]" target=3D"_blank">saxon-help@=
lists.sourceforge.net</a><br><a href=3D"https://lists.sourceforge.net/lists=
/listinfo/saxon-help" target=3D"_blank">https://lists.sourceforge.net/lists=
/listinfo/saxon-help</a> </p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></di=
v></body></html>=

--_5B4FC50C-2DF7-4BCF-B842-E7FB35EE50BA_--



--===============0913596590880576117==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============0913596590880576117==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
--===============0913596590880576117==--