I'm using some Java methods in xsl like below :
<xsl:variable name="inSDF" select="SimpleDateFormat:new($datePattern)"/>
When i'm executing xsl from Eclipse with Xalan processor, its ok. But when I'm executing on server within a software with the same Xalan version, I get the following error :
XalanXPathException: The function number
'java.text.SimpleDateFormat:new' is not available
Why does this error occur ? What should I check on the server ?
Thank you.
The XalanXPathException looks like a Xalan-C exception, not a Xalan-J exception. Is your server is running Xalan-C? Your code looks like it trying to call a Java constructor, but that won't be available in Xalan C.
If you're trying to format a date in XSLT 1.0 running on Xalan-C, the documentation indicates it supports the EXSLT library.
https://apache.github.io/xalan-c/extensionslib.html
http://exslt.org/date/date.html
Related
What is the recommended way in Saxon to load in an XML document from eXist-db via XQuery GET/POST within an XSL stylesheet? I want to run an XQL query in eXist-db, which should be simple enough to do as a GET with <xsl:variable name="test" select="doc('xmldb:exist:///db/test.xql')"/> or <xsl:variable name="test" select="doc('http://localhost:8080/exist/rest/db/test.xql')"/>. But the former doesn't exectute the query and tries to return the XQL source as XML, and the latter doesn't have the basic authentication to execute. Also, I really want to send an XML fragment using POST, and have the XQL use that posted XML fragment.
I can't find anything in the Saxon documentation about this. I did find an old EXPath article at http://expath.org/modules/http-client/samples, but the downloads there are 7 years old, and may not work with modern Saxon. So looking for the best known method to do this.
The first thing that comes to mind is the EXPath HTTP Client module. There's no way to persuade the doc() or document() functions to do POST instead of GET, AFAIK.
I am using saxon xslt processor and python script to perform xslt transformations. I want to add exception handling to the python script. The saxon processor has inbuilt exceptions which are raised with codes (eg., SXXP003) etc. These error messages are displayed in the console because i am executing saxon files using batch file. The issue is that the saxon errors are not being written to traceback stack in python because of which i am unable to retrieve the error message. please provide a solution for the problem. I want to display the saxon error in the try except of python.
Regards
Anshul Mittal
Python has a number of different ways of invoking external programs via their command line interface: check whether the method you are using has any way of redirecting the System.err output stream. (I don't know Python so I can't advise on that aspect). If you can find a way to do this, then you can try to parse the error messages and extract the error codes.
A different approach, which might perform better and would give you more control (but which might involve more effort to configure correctly), would be to use the new Saxon/C product and invoke it via its C APIs, instead of invoking the Java product via its command-line interface.
In addition to Mike's reply, a python interface for Saxon/C is in development and worth a look:
https://github.com/ajelenak/pysaxon
I am using the saxonb9-1-0-8j processor.
I am running my transformation using the <xslt> task in Ant.
I would like to use Saxon's extension functions such as saxon:line-number().
I have found that the -I option allows line numbering for the current document (reference).
My question is: How to allow line numbering via the <xslt> task?
The Ant documentation for <xslt> says there should be a nested attribute element to pass processor specific settings. However, I wasn't able to find the correct syntax.
How can I use Saxon extension functions like saxon:line-number() with Ant?
Try
<factory name="net.sf.saxon.TransformerFactoryImpl">
<attribute name="http://saxon.sf.net/feature/linenumbering" value="true"/>
</factory>
The suggestion is based on the 9.5 documentation http://saxonica.com/documentation9.5/using-xsl/xsltfromant.html, I would guess it is not different in 9.1, check its documentation yourself at http://saxon.sourceforge.net/ if needed.
We've been pulling our hair out just trying to just trying to get a basic example of the XSLT replace function to work.
I'm leaving this text in tact for context, but you may want to skip to the update
We're using Mirth to pull in HL7 messages. We're unsure whether this supports XSLT version 2, but we believe it uses SAXON - http://saxon.sourceforge.net/, which purportedly does support XSLT2 and hence the replace function.
In any case, we tried using XSLTCake to try and get even a demo replacement to work, to no avail. We've seen this either referenced as replace or fn:replace as well as a couple other suggestions using other libraries.
If XSLT2 isn't supported by Mirth, we would need a workaround for XSLT1. We found one here: XSLT string replace - but have been unable to get this to work either.
This is a tough to get down to a single question as I'm asking alot, but here goes... Can anyone provide a working example of performing a regex replacement in an XSLT? Preferably one that will run in an online parser for reference.
Here's a sample - which apparently should work.1
Update
Thanks to Michael Kay for providing code below to determine XSLT version.
<!--Transformed using 1.0 provided by Apache Software Foundation (Xalan XSLTC)-->
So It turns out we were all wrong about Mirth using SAXON and hence supporting XSLT2. I'll update with our attempt at implementing the version 1 workaround.
First find out which XSLT processor you are using. This is straightforward: insert this
<xsl:comment>Transformed using <xsl:value-of select="system-property('xsl:version')"/> provided by <xsl:value-of select="system-property('xsl:vendor')"/></xsl:comment>
into your stylesheet to output a comment in your result document.
Once you know what programming language you are using, you can start thinking about writing code.
I get the error message:
"Cannot find a matching 1-argument function named
{http://exslt.org/common}node-set()"
when running a xslt transformation with the Saxon engine.
I've tried using Saxon PE and EE on Windows XP and it gives the same error. EXSLT should work out of the box with Saxon. Does anyone have a solution on how I may resolve this, please?
Saxon PE and EE are XSLT 2.0 processor implementations where you don't need a node-set extension function as in XSLT 2.0 the difference between result tree fragments and node-sets does no longer exists. So you should be able to simply use e.g. $var/foo/bar instead of exsl:node-set($var)/foo/bar in your stylesheets where you process variables.