Calc: XSLT 2.0 filter for import

Hi there.

Need a bit of help with using XSLT 2.0 functions for Calc import, I want to implement fn:replace (which is XSLT 2.0) in one of my filters. While using pure XSLT 1.0 filters all is working fine, but when I register xsl:stylesheet version="2.0"and tick The filter needs XSLT 2.0 processor, xml file opening process returns General Input/Output error. Made some attempts with cdcatalog.xml from https://www.w3schools.com/xml/cdcatal... and with this XSLT filter (for readability I removed other namespaces, they are the taken from content.xml and work fine with XSLT 1.0):


< ?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" <office:body="">
<table:table>
<xsl:for-each select="catalog/cd">
<table:table-row>
<table:table-cell office:value-type="string" calcext:value-type="string">
<text:p><xsl:value-of select="replace(title, 'a','')"/></text:p>
</table:table-cell>
</table:table-row>
</xsl:for-each>
</table:table>
</office:body>
</office:document-content>
</xsl:template>
</xsl:stylesheet>


I always get General Input/Output error when trying to apply Replace function. no matter The filter needs XSLT 2.0 processor is enabled or disabled. Changing fn:replace with fn:translate and unticking needs XSLT 2.0 makes things work as expected. Am I missing something obvious in code or in Calc settings?

LO Version: 6.0.4.2 Build ID: 9b0d9b32d5dcda91d2f1a96dc04c645c450872bf CPU threads: 2; OS: Windows 6.1; UI render: default; Locale: en-GB (lv_LV); Calc: group

edit retag close merge delete

NB. There is no first whitespace between < and ? in actual code on the first line <?xml version="1.0" encoding="utf-8"?>, this forum's engine just does not show the line while whitespace is not there.

( 2018-08-21 21:36:43 +0200 )edit

To avoid the need of additional extensions as dependencies of your solution, i.e. limiting yourself to XSLT 1.0, you would need to implement replace operation yourself. For one example, see https://habr.com/ru/post/71186/ (the article is in Russian; the relevant listing is the first in the article).

( 2019-11-17 08:02:50 +0200 )edit

It seems to me, that this is the exact place I earlier took code snippet from to make things done with XSLT 1.0 :) Oh and Russian is my native language, so no problem with the source provided.

( 2019-11-17 10:23:06 +0200 )edit

Sort by » oldest newest most voted

For those, who are interested in solution.

Seems like, at least to me, that Calc do not provide "out of the box" solution to work with XSLT 2.0. While creating new XML Filter, it is possible to check option The filter needs XSLT 2.0 processor, but it is not just enough to proceed with XSLT 2.0. In fact, enabling this option only tells Calc that transformation file has some XSLT 2.0 specific contents, which native Calc instruments can not handle anyway.

Luckily, there is an xslt2-transformer extension, which can provide the functionality needed. But, while Install Instructions calmly state that all we need to do is just to download extension and add downloaded OXT file via Extension Manager, a bit of nightmare for common Windows user begins. The extension page offers some kind of a quest "try to find download link", which leads to the github project page with extension's source code. But, there is no desired .OXT file though, only some "no-extension" and text files. "Hello, big real world!" and congrats, we just made our first step out of the Windows sandbox.

Remark, many thanks to @Mike Kaganski. New xslt2-transformer release now comes with prebuilt and ready to use xslt2-transformer.oxt file, so for the most Windows OS users there is no need for these woodoo'ish things mentioned below anymore. Those, who are interested in building extension by themselves for educational or any other reason, are welcome to read further.

Before we can use this extension, we need to build it, literally. In the real world, to rise a building, you need materials, blueprints and workers. To build an extension, you need the source code (aka materials), makefile, which defines how building shall proceed (aka blueprint) and environment, which is capable and knows how to use makefile and to actually execute building procedure (aka workers). Ok, we have downloaded the source code, makefile is inside, what about an environment for Windows OS? I used Cygwin, probably CMake and Visual Studio can handle it too. As for Cygwin, zip extension shall be installed in order to run makefile successfully. Cygwin installation instructions.

Before building extension, slight adjustment shall be made in Makefile, open it with any text editor and change XCLASSPATH := external/saxon9.jar:$(CLASSPATH) line to XCLASSPATH := external/saxon9.jar;C:/Path/to/LO/installation/LibreOffice/program/classes/*$(CLASSPATH) Adjust the link according to your LO path. After Cygwin is installed, run Cygwin Terminal, navigate to folder, where xslt2-transformer extension is downloaded (type cd c:/path/to/folder) and type make.

Possible error can be in jar -cfm instruction on line 30 of a makefile. Cygwin adds /cygdrive/ prefix to absolute path, which points to non existing location and results in incorrect path for instruction. If so, just hardcode path in this line jar -cfm C:/path/to/extension/xslt2-transformer-master/build/ext/xslt2-transformer.jar C:/path/to/extension/xslt2-transformer-master/Manifest com If the building completes successfully, you will find newly created build folder ...

more

1

Nice!

Wanted to mention that David has published a release there 23 days before - likely after you already did everything manually, but still hopefully this information would be helpful to someone.

Also worth explicit mentioning (for those who might be unfamiliar with all those JARs) is that the extension needs Java/JRE.

( 2019-11-17 07:27:50 +0200 )edit

I should have double checked extension page prior to writing, my answer could be about 5 times shorter :) Anyway, at least I am very glad to learn something new, so much different from just clicking the download link :)

( 2019-11-17 09:07:12 +0200 )edit
1

It's always great to learn new things - even if by mistake :-) - thanks for posting; hope that others would also enjoy/learn useful things.

( 2019-11-17 09:17:19 +0200 )edit