Project

Profile

Help

Bug #4815

open

Conversion of XDM maps to JS objects

Added by Debbie Lockett over 3 years ago. Updated almost 2 years ago.

Status:
New
Priority:
Normal
Category:
IXSL extensions
Sprint/Milestone:
Start date:
2020-10-30
Due date:
% Done:

0%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

On the XML.com Slack general channel, Pieter Lamers asked the following:

I'm trying to get scrollIntoView to work smoothly. Now, ixsl:call($target, 'scrollIntoView',[]) works, but I don't know how to pass the ScrollIntoViewOptions into the array. [...] This is what I would typically want to achieve: element.scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});

Intuitively, users expect to be able to supply a map(*) in the array for the 3rd argument to ixsl:call; but this will not work as expected, because the XDM to JS conversion does not automatically convert XDM maps to JavaScript object literals. (See https://www.saxonica.com/saxon-js/documentation/index.html#!xdm/conversions). Instead if an XDM map is supplied here, it will be converted to a "wrapped XDM map object", which the scrollIntoView JavaScript method simply ignores.

Martin Honnen suggested a couple of work arounds:

you might want to set up a Javascript variable var options = {behavior: "smooth", block: "start", inline: "nearest"}; and pass it to the XSLT with e.g. SaxonJS.transform({ stylesheetLocation: 'sheet1.sef.json', sourceLocation: 'sample1.xml', stylesheetParams: { options: options } } ) In your XSLT you then use ixsl:call(., 'scrollIntoView', [ $options]) and declare <xsl:param name="options" required="true"/>

Or construct the scroll options inside XSLT with e.g. <xsl:param name="scrollOptions" as="xs:string" expand-text="no">{ "behavior" : "smooth", "block" : "start", "inline": "nearest" }</xsl:param> and ixsl:call(., 'scrollIntoView', [ ixsl:window() => ixsl:call('JSON.parse', [ $scrollOptions ]) ]). Seems a bit cumbersome, not sure whether there is a simple way to convert an XdmMap into a JavaScript object inside of Saxon-JS.

Indeed currently our recommended approach is that if you really want/need to work with JavaScript objects, then create them in the JavaScript space, since converting from XDM maps is not possible. But either: (a) this needs to be made clearer in the documentation; or (b) as Martin alludes, perhaps we should actually be providing a way to ask for (certain) XDM maps to be converted to JavaScript objects from the XSLT (e.g. with a new IXSL function).

Please register to edit this issue

Also available in: Atom PDF Tracking page