Re: [Saxon-JS 2] Creating a JSON object
Martynas Jusevičius <martynas-tyFqBaoSXPC1Z/[email protected]>
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <CAE35Vmxz4oXi5suuA858wDwQ+tnSHtLscL3FWpr2NeMfaNcqpw@mail.gmail.com> |
Right, the attribute is a leftover from the Saxon-CE code... I found this snippet somewhere, I think the intention is to be able to use the attribute value template to inject values. But I can see that || in XSLT 3 does pretty much the same. This code is calling methods on a JS library which builds a SPARQL query string in the end. It all works fine through ixsl:call(), it's just the object creation that requires ixsl:eval(). On Fri, Sep 4, 2020 at 11:45 PM Michael Kay <[email protected]> wrote: > > I can't see why you want to create an attribute in order to extract its string value. Why not just construct the string in the first place? > > <xsl:variable name="js-statement" as="xs:string" > select="{ subject: SPARQLBuilder.SelectBuilder.var('child'), > predicate: SPARQLBuilder.SelectBuilder.var(' || $predicate || '), > object: SPARQLBuilder.SelectBuilder.var('whatever') }"/> > > Apart from that, if you really need to write the application by generating Javascript dynamically and then evaluating it, then I don't think it's going to much simpler than this. But I can't really judge whether that is actually the right design. > > Michael Kay > Saxonica > > > > " > > select="ixsl:eval()"/> > > > On 4 Sep 2020, at 21:39, Martynas Jusevičius <[email protected]> wrote: > > > > Hi, > > > > Is there a quicker/cleaner way to create a JSON object and store it in > > a variable than this? > > > > <xsl:variable name="js-statement" as="element()"> > > <root statement="{{ subject: > > SPARQLBuilder.SelectBuilder.var('child'), predicate: > > SPARQLBuilder.SelectBuilder.var('{$predicate}'), object: > > SPARQLBuilder.SelectBuilder.var('whatever') }}"/> > > </xsl:variable> > > <xsl:variable name="bgp" > > select="ixsl:eval(string($js-statement/@statement))"/> > > > > $bgp is later being used like this: > > > > > > _______________________________________________ > > saxon-help mailing list archived at http://saxon.markmail.org/ > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/saxon-help > > > > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help