xsl-list
[Top] [All Lists]

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

2016-07-07 07:28:13
First, apologies for my status as an XSLT user.  I know enough to be dangerous, 
but not enough to understand how or why!  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).  I definitely need to pass JSON data to JS 
functions.  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.  
(Looking into that -- Heck, it might be  superior to passing HTML as a string.  
What's important is being able to inject data from the product API as I 
generate the result.  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.  The trick is getting a string into a variable -- Then I can pass 
that easily enough.  (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:" 
    
<p>arf</p>

    
<p>woof</p>

    
<p>bark</p>

    "}

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

Here's the XSLT that I use to make the JSON string.  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/>    "}</xsl:copy>
</xsl:template>

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

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Saxon-CE -- Passing Data to a JS Function, Chris Despopoulos despopoulos_chriss(_at_)yahoo(_dot_)com <=