[Saxon-CE] Initiating update of an HTML element from JavaScript

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Saxon-CE] Initiating update of an HTML element from JavaScript

Martynas Jusevičius
Hey,

I have the following use case and I'm struggling to put the pieces together:
- a <form> element in HTML that needs to be updated
- an XML document loaded using $.ajax()
- a template with a mode, which produces <form> from the XML document

I want to initiate the update from JavaScript.

This is a test template, instead of the actual (which produces <form>):

    <xsl:template match="/" mode="ConstructMode">
        <xsl:message>TRANSFORM??</xsl:message>
    </xsl:template>

This is the JS code:

xslt2proc.setInitialMode("ConstructMode");
var fragment = xslt2proc.transformToHTMLFragment(jqXHR.responseXML,
$(document)[0]);
console.log("xslt2proc.getResultDocument():" + xslt2proc.getResultDocument());
console.log("fragment: " + fragment);


Yet I don't see the xsl:message in the console log, so I assume it was
not executed:

13:14:59.302 Commencing transform type:TRANSFORM_TO_HTML_FRAGMENT

SaxonCE.XSLT20Processor 13:14:59.296
FINE: Commencing transform type:TRANSFORM_TO_HTML_FRAGMENT

CECE12D...he.html (line 875)
13:14:59.330 Transform complete

SaxonCE.XSLT20Processor 13:14:59.328
FINE: Transform complete

CECE12D...he.html (line 875)
xslt2proc.getResultDocument():[object HTMLBodyElement]
jquery.js (line 41)
fragment: undefined


What am I doing wrong?

Thanks.


Martynas
atomgraph.com

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: [Saxon-CE] Initiating update of an HTML element from JavaScript

Martynas Jusevičius
OK, my bad: I am reusing the Processor and forgot to clear the initial
template. xslt2proc.setInitialTemplate(null) fixed the problem, I can
see the template being applied now.


However, transformToHTMLFragment() seems to append the transformation
to the end of <body>? When I instead want to replace the existing
<form> form with it, myself.

The documentation says that updateHTMLDocument() does that -- but does
not say that about transformToHTMLFragment()?
http://www.saxonica.com/ce/user-doc/1.1/index.html#!api/xslt20processor/transformToHTMLFragment


There is also another problem - the Clark-notation does not seem to
work for template modes (the namespace is ignored):

  xslt2proc.setInitialMode("{http://graphity.org/xsl/bootstrap/2.3.2}ConstructMode");

It logs:

SaxonCE.XSLT20Processor 13:45:22.863
SEVERE: XPathException in invokeTransform: Requested initial mode
ConstructMode does not exist

While I have

    xmlns:bs2="http://graphity.org/xsl/bootstrap/2.3.2"

    <xsl:template match="rdf:RDF" mode="bs2:ConstructMode">

Martynas

On Sun, Jul 3, 2016 at 1:29 PM, Martynas Jusevičius
<[hidden email]> wrote:

> Hey,
>
> I have the following use case and I'm struggling to put the pieces together:
> - a <form> element in HTML that needs to be updated
> - an XML document loaded using $.ajax()
> - a template with a mode, which produces <form> from the XML document
>
> I want to initiate the update from JavaScript.
>
> This is a test template, instead of the actual (which produces <form>):
>
>     <xsl:template match="/" mode="ConstructMode">
>         <xsl:message>TRANSFORM??</xsl:message>
>     </xsl:template>
>
> This is the JS code:
>
> xslt2proc.setInitialMode("ConstructMode");
> var fragment = xslt2proc.transformToHTMLFragment(jqXHR.responseXML,
> $(document)[0]);
> console.log("xslt2proc.getResultDocument():" + xslt2proc.getResultDocument());
> console.log("fragment: " + fragment);
>
>
> Yet I don't see the xsl:message in the console log, so I assume it was
> not executed:
>
> 13:14:59.302 Commencing transform type:TRANSFORM_TO_HTML_FRAGMENT
>
> SaxonCE.XSLT20Processor 13:14:59.296
> FINE: Commencing transform type:TRANSFORM_TO_HTML_FRAGMENT
>
> CECE12D...he.html (line 875)
> 13:14:59.330 Transform complete
>
> SaxonCE.XSLT20Processor 13:14:59.328
> FINE: Transform complete
>
> CECE12D...he.html (line 875)
> xslt2proc.getResultDocument():[object HTMLBodyElement]
> jquery.js (line 41)
> fragment: undefined
>
>
> What am I doing wrong?
>
> Thanks.
>
>
> Martynas
> atomgraph.com

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help