I'm trying to use the XSLT Mediator using XSLT version "3.0".but i can't use following XSLT transformation.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output version="1.0" encoding="UTF-8" omit-xml-declaration="yes" indent="true"/>
<xsl:variable name="data" select="//return => json-to-xml()"></xsl:variable>
<xsl:template match="/" xpath-default-namespace="http://www.w3.org/2005/xpath-functions">
<ns1:root xmlns:ns1="http://urldata.com/ns1">
<ns1:MessageData>
<xsl:value-of select="$data//boolean[#key = 'accountstatus']"/>
</ns1:MessageData>
<ns1:Code>
<xsl:value-of select="$data//map[#key = 'response']/string[#key = 'Code']"/>
</ns1:Code>
<!--- use this approach for everything you want to select ... -->
</ns1:root>
</xsl:template>
</xsl:stylesheet>
The error i'm getting is: net.sf.saxon.trans.LicenseException: Requested feature (XSLT 3.0) requires Saxon-PE
get Saxon-HE 9.8 using below URL
https://sourceforge.net/projects/saxon/files/Saxon-HE/9.8/
And download most downloaded version and put it below path to your esb configuration
wso2esb-4.9.0/lib/
and restart the service
XSLT 3.0 was supported in the commercial versions of Saxon while it was still under development, but support moved into the open source version Saxon-HE only when the W3C spec was finalised. Try a later version of Saxon - the current version is 10.3.
Related
I have two XSL file, one XSL importing another one ,
Not getting any value in the variable data. The variable data I am using below to get the attributes. Since the data is empty. Not getting values from it. is there anything wrong in this line <xsl:variable name="data" select="$header/sections/code[#key=$key]"/>
XSL 1 : Veichle.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="Motor.xsl"/>
<xsl:output omit-xml-declaration="yes" method="xml" />
<xsl:param name="key" select="'vita'"/>
</xsl:transform>
XSL 2: Motor.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f1="urn:hl7-org:v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cda="urn:hl7-org:v3"
xmlns:sdtc="urn:hl7-org:sdtc" xpath-default-namespace="http://hl7.org/fhir"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:lookup="http://lookup.data"
xmlns:uuid="java:java.util.UUID" exclude-result-prefixes="fn lookup uuid sdtc cda xsl xsi f1">
<xsl:import href="section.xsl"/>
<xsl:output omit-xml-declaration="yes" method="xml"/>
<xsl:param name="key" select="'results'"/>
<xsl:param name="mostRecent" select="false()"/>
<xsl:variable name="header">
</xsl:transform>
The expression $header/sections/code/[#key=$key] wasn't valid in XPath 1.0, 2.0 or 3.0. In XPath 3.1 it has a meaning (it returns an array), but it's not the meaning you think it has. As Martin explains, you probably intended $header/sections/code[#key=$key], but I don't know why your previous XSLT processor didn't flag an error.
In addition to the namespace issue pointed out in the comment, i.e. to set xpath-default-namespace="http://hl7.org/fhir" where you want to select elements from that namespace, the other error in your code is in the section $header/sections/code/[#key=$key] where you probably want $header/sections/code[#key=$key], i.e. a boolean predicate on the last step for the code elements.
If you really upgraded from XSLT 1 or 2 to Saxon 10, then I would think for older processors the expression you have should have given you an error and in XSLT 3 it would create a sequence of arrays with a boolean value.
When I try to run this XSLT style sheet (adapted from http://www.oxygenxml.com/archives/xsl-list/201001/msg00361.html) with Saxon 9.1.0.8 or Saxon-HE 9.5.1.3J, I get an empty output file.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" version="2.0">
<xsl:output saxon:recognize-binary="yes" method="text"/>
<xsl:template match="/">
<?hex 07?>
<xsl:processing-instruction name="hex" select="'07'"/>
</xsl:template>
</xsl:stylesheet>
From the Saxon documentation and the message mentioned above, I would have expected that the output is a string containing one (or two) ^G characters. Why did I not get any output at all?
Custom serialization requires Saxon-PE (or EE).
You should've gotten an error similar to this:
Transformation failed: Requested feature (custom serialization
{http://saxon.sf.net/}recognize-binary) requires Saxon-PE
http://saxonica.com/documentation/index.html#!extensions
I tried it with Saxon-EE 9.3.0.5 and it works.
Note that you need the xsl:processing-instruction form. Literal PIs in a stylesheet are stripped out, they do not cause processing instructions to be sent to the output.
In order to use xpath-functions (specifically the fn part), I included the respective namespace into my xslt stylesheet, like so:
<xsl:stylesheet
version="2.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
>
As specified by W3C.
However, when I use fn:document-uri, my XSLT engines tell me I called an unknown function/extension:
<xsl:variable name="uri" select="fn:document-uri()" />
Opera says:
This document had an invalid XSLT stylesheet. Error message from the XSLT engine:
Error: XPath expression compilation failed: fn:document-uri()
Details: compilation error (characters 1-17, "fn:document-uri()"): unknown function called: '{ http://www.w3.org/2005/xpath-functions, document-uri }'
Firefox says:
Error during XSLT transformation: An unknown XPath extension function was called.
And xsltproc refuses transformation, because of xslt 2.0.
So, how do I specify the fn namespace properly?
The problem is that you are using an XSLT 1.0 processor and an XSLT 1.0 processor doesn't know (and must not know) anything about XPath 2.0 functions.
If you use a real XSLT 2.0 processor, you don't even have to specify the function namespace -- it is a default namespace for any unprefixed function name.
For example, this XSLT 2.0 transformation:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:sequence select="document-uri(.)" />
<xsl:text>
</xsl:text>
<xsl:sequence select="document-uri(document(''))" />
</xsl:template>
</xsl:stylesheet>
when executed with Saxon 9.1.5 under the XSelerator, produces correctly the URLs of the source XML document and the stylesheet itself:
file:/C:/Program%20Files/Java/jre6/bin/marrowtr.xml
file:/C:/Program%20Files/Java/jre6/bin/marrowtr.xsl
I have an XSL which generates a XML file
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="filename" select="concat('TextTypes','.html')" />
<xsl:result-document method="html" href="{$filename}">
<font name="{$truncatedFont}" size="{$truncatedSize}" style="{#styleOverride}" env="{$env}" lang="{#language}" />
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
When I run the XSLT i get the error:
ERROR: 'Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:result-document''
Error during transformation
javax.xml.transform.TransformerException: java.lang.RuntimeException: Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:result-document'
I have specified ny XSLT verision as 2.0. I am confused on why i get this error. Please help.
XSLT 2.0 is only supported by a few XSLT processors, I think with Java there is only Saxon 9 and with IBM's websphere you can also use IBM's XSLT 2.0 processor but the XSLT processor in the Oracle respectively SUN JRE and JDK is based an Apache Xalan and only supports XSLT 1.0.
Looks like your xslt processor does not support version 2.0.
It depends on how you're running your XSLT nishMaria.
If you can daisy chain XSLT then you can process the input document multiple times to produce multiple different output files or produce one output file with all the desired output then pass this file through a number of XSLT's each of which just selects part of the output.
Good day! I downloaded Altova XMLSpy trial, installed FOP 0.95 and tried to perform XSLT (version 1.0) transformation. My template is valid but during the transformation it fails on the line containing "date-time()" function:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:dt="http://exslt.org/dates-and-times" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="dt exsl">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="dt:date-time()"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The error message is:
Error in XPath expression
Unknown function - Name and number of arguments do not match any function signature in
the static context - 'http://exslt.org/dates-and-times:date-time'
Please how to make this function available? I'm sure this function exists. The template works for example in this online XSLT tester: http://markbucayan.appspot.com/xslt/index.html
Thank you in advance! Vojtech
UPDATE: I installed SAXON 9 (both HE and EE), configured ALTOVA to use it but again the same error.
If you are using Altova or saxon you can use XSLT2 rather than XSLT1 so do not need to load the EXSLT extensions, xpath2 has this function built in
select="current-dateTime()"
http://www.w3.org/TR/xpath-functions/#func-current-dateTime
`<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" extension-element-prefixes="msxsl" xmlns:local="urn:local>
<msxsl:script language="CSharp" implements-prefix="local">
public string dateTimeNow()
{
return DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
}
</msxsl:script> </xsl:stylesheet>`
and then use it like this <xsl:param name="dnes" select="local:dateTimeNow()"/>
Please use Altova xml spy 9 version which support XSL 2.0.
Thanks
Aditya