Project

Profile

Help

How to get updated versions of documents via doc()?

Added by Philipp Müller over 6 years ago

Currently I'm implementing a webtool using Saxon-JS. This tool is aimed at enabling the display and transformation of certain XML documents containing business logic.

On pageload, I only load the documents needed for the structure of the start page and then asynchronously load the other input-XML-documents, which works fine. The user can change information presented on the page without reloading the whole page: If the user clicks on the menu, the sites hash is transformed, which triggers the display of the relevant data (a different category). When the user changes data (e.g. input in a form), an update is sent via POST to the server, where the relevant input-XML-document is updated via xQuery. Then the data to be displayed is asynchronously loaded with a GET-request. After that, the updated data is displayed, without reloading the whole page. This also works fine.

If the user then clicks on a different menu entry and then returns to the previous category (where changes were applied before), the old, outdated information is displayed. If I reload the whole page, then the correct data is displayed again.

During the described procedure the file "test.xml" is fetched via GET twice. However if I use doc("'test.xml'") always the first version is chosen, resulting in the display of outdated data.

Is this because doc() attempts to find the file in the available documents https://www.w3.org/TR/xpath-30/#eval_context - and there already is a mapping from this string to the old document node? Is it possible to choose the latest file-version?

I'm happy to provide additional information if needed.

Thanks in advance! Philipp


Replies (3)

Please register to reply

RE: How to get updated versions of documents via doc()? - Added by Michael Kay over 6 years ago

XSLT is designed to be purely functional, and therefore it's a rule for the doc() function that if you call it twice with the same argument, you get the same answer.

For Saxon-JS we've had to find ways to relax the purely functional behaviour because when you're writing interactive applications you have to interact with a changing world.

There may be other ways of doing it, but the first thing that comes to mind is to use the http-request capability on ixsl:schedule-action rather than using the doc() function. This also plays better into the requirement not to issue synchronous requests to the server.

RE: How to get updated versions of documents via doc()? - Added by Debbie Lockett over 6 years ago

With the next release Saxon-JS 1.1.0 (coming soon!), another way to do it will be to use the Saxon extension function saxon:discard-document() which can be used to remove a document from Saxon-JS's local cache, and then you can reload an updated version with a subsequent doc() fetch (see Feature #3571, and http://www.saxonica.com/documentation/index.html#!functions/saxon/discard-document).

RE: How to get updated versions of documents via doc()? - Added by Philipp Müller over 6 years ago

Thanks a lot for your answers.

This is what I'm doing at the moment: If an input file changes, I use ixsl:schedule-action to get a new version of that file. After that I would like to operate based on that file

The problem arises as soon as for example the user clicks on a button:



    ... ...

After that template is triggered, I needed a way to access the previously loaded xml input file.

The solution with discard-document() sounds very promising - I'm looking forward to the new Saxon-JS release and will try it then, thanks!

In the meantime I'm writing the serialized xml to the session storage and read from there as an ugly workaround.

    (1-3/3)

    Please register to reply