[xsl] Saxon-CE -- Passing Data to a JS Function

Subject: [xsl] Saxon-CE -- Passing Data to a JS Function
From: "Chris Despopoulos despopoulos_chriss@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jul 2016 12:28:07 -0000
First, apologies for my status as an XSLT user.B  I know enough to be
dangerous, but not enough to understand how or why!B  I'm working on it (Yes,
I have the big book by Dr. Kay).
I'm trying to use Saxon-CE for DITA to HTML transforms in the browser (instead
of the browser's XSLT engine).B  I definitely need to pass JSON data to JS
functions.B  I would like to pass generated HTML to JS functions as well, but
I might be able to make the result-document mechanism work for my existing
app.B  (Looking into that -- Heck, it might beB  superior to passing HTML as a
string.B  What's important is being able to inject data from the product API
as I generate the result.B  I'm guessing Saxon-CE can do that.)

Anyway, I originally had problems passing data to JS, but I've got the JSON
part working.B  The trick is getting a string into a variable -- Then I can
pass that easily enough.B  (Thanks for the help so far!!!)
For example, for this XML:
<items><item>arf</item><item>woof</item><item>bark</item></items>

I can get this string into an alert...{foo : arf, bar : content:"
B B B 
<p>arf</p>

B B B 
<p>woof</p>

B B B 
<p>bark</p>

B B B  "}

Sure would like to get rid of the extra line returns, but that's lower
priority.B  Declaring the variable as a string and copying the results into
the variable seems to do the trick.B  A question is...B  How would I generate
HTML and copy THAT into a variable that I can pass to JS?B  I suspect that JS
is ignorant of XSLT tree objects...
<advance>Thanks</advance>B  (Thanks in advance for any help)

Here's the XSLT that I use to make the JSON string.B  Is this more or less the
transform structure you would use -- Global variable populated by named
template (or maybe templates of a mode???), call the function for the doc
node, and match the input XML structure in all the other templates?

<xsl:variable name="myTree" as="xs:string"><xsl:call-template
name="TRY_THIS"/></xsl:variable>

<xsl:template match="/"><xsl:call-template name="callFunc" /></xsl:template>

<xsl:template match="items/item">&lt;p&gt;<xsl:value-of
select="normalize-space(.)"/>&lt;/p&gt;</xsl:template>

<xsl:template name="TRY_THIS">
<xsl:copy>{foo : arf, bar : content:" <xsl:apply-templates/>B B B 
"}</xsl:copy>
</xsl:template>

<xsl:template name="callFunc"><xsl:value-of
select="js:myFunc($myTree)"/></xsl:template>

Current Thread