[Saxon-JS 2] Creating and referencing an element

Martynas Jusevičius <martynas-tyFqBaoSXPC1Z/[email protected]>
Newsgroups gmane.text.xml.saxon.help
Message-ID <CAE35VmzFLEHLRyE_Vs-rJzBaeWmFGwjvr9OHOJOoCAzCNLa90g@mail.gmail.com>
Hi,

with Saxon-CE I used this kind of approach within <xsl:result-document>:
- output a <div> element with ID
- look it up by ID using document.getElementById()
- pass it to Google Maps object constructor

The same code doesn't work with Saxon-JS -- I get "Map: Expected
mapDiv of type Element but was passed null."

I guess it only worked because of the <ixsl:schedule-action wait="0">
(see the Saxon-CE code below).

The only relevant mention I could find in the documentation is this:

    Saxon-CE implemented a "pending update list" so that HTML page
modifications such as xsl:result-document and ixsl:set-attribute were
deferred until the end of the current transformation phase. This is
not implemented in this release of Saxon-JS.

Not sure exactly what it means -- that <ixsl:schedule-action wait="0">
should not be required anymore?

I tried moving the object creation after the <xsl:result-document>,
but that didn't help -- no error but the map object is left undefined
(with or without <ixsl:schedule-action wait="0">).

What is the solution here?

=== Code ===

<xsl:template match="*[@id = 'container-pane']/div/ul[@class = 'nav
nav-tabs']/li/a" mode="ixsl:onclick">
    <xsl:result-document href="?." method="ixsl:replace-content">
        <xsl:call-template name="container-mode"/>
    </xsl:result-document>
</xsl:template>

<xsl:template name="container-mode">
    <xsl:param name="canvas-id" select="'map-canvas'" as="xs:string"/>

    <div id="{$canvas-id}"></div>

    <ixsl:schedule-action wait="0">
        <xsl:call-template name="create-google-map">
            <xsl:with-param name="map"
select="ac:create-map($canvas-id, 56, 10, 4)"/>
        </xsl:call-template>
    </ixsl:schedule-action>
</xsl:template>

<xsl:template name="create-google-map">
    <xsl:param name="map"/>

    <ixsl:set-property name="map" select="$map"
object="ixsl:get(ixsl:window(), 'LinkedDataHub')"/>
</xsl:template>

<xsl:function name="ac:create-map">
    <xsl:param name="id" as="xs:string"/>
    <xsl:param name="lat" as="xs:float"/>
    <xsl:param name="lng" as="xs:float"/>
    <xsl:param name="zoom" as="xs:integer"/>

    <xsl:variable name="js-statement" as="element()">
        <root statement="new
google.maps.Map(document.getElementById('{$id}'), {{ center: new
google.maps.LatLng({$lat}, {$lng}), zoom: {$zoom} }})"/>
    </xsl:variable>
    <xsl:sequence select="ixsl:eval(string($js-statement/@statement))"/>
</xsl:function>


Martynas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.