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 Empire Burlesque 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"?>


<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  
    
                     
        
         
          
            
          
         
        
      
    
  



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

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.

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 Мелочи в XSLT 1.0 / Хабр (the article is in Russian; the relevant listing is the first in the article).

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

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 @mikekaganski. 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 in the extension’s directory and desired xslt2-transformer.oxt file inside.

All to do left is to navigate to Tools -> Extension Manager, add xslt2-transformer.oxt file and voila. Now Calc is capable to handle XSLT 2.0 specific content. Worth noting, extension needs Java/JRE to be installed on your machine (once again, thanks to @mikekaganski for pointing out)

P.S> Probably, using and adjusting makefiles, compiling and building from sources is an easy daily routine, for me as windows-only user it was the path of learning and struggling.

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.

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

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