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
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.
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.
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.
I'm an XSLT newbie, and need to use XSLT to extract some fields from a trademark file from the US Patent and Trademark Office. Here's a very simplified copy of a typical file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Transaction xmlns:ns2="urn:us:gov:doc:uspto:trademark:status" xmlns="http://www.wipo.int/standards/XMLSchema/trademarks">
<TradeMarkTransactionBody>
<TransactionContentDetails>
<TransactionCode>National Trademark Information</TransactionCode>
<TransactionData>
<TradeMarkDetails>
<TradeMark>
<RegistrationOfficeCode>US</RegistrationOfficeCode>
<ApplicationNumber>74631225</ApplicationNumber>
<ApplicationDate>1995-02-07-05:00</ApplicationDate>
<RegistrationNumber>2178784</RegistrationNumber>
<RegistrationDate>1998-08-04-04:00</RegistrationDate>
<FilingPlace>US</FilingPlace>
<MarkCurrentStatusDate>2008-08-11-04:00</MarkCurrentStatusDate>
<WordMarkSpecification>
<MarkVerbalElementText>JAVA </MarkVerbalElementText>
</WordMarkSpecification>
</TradeMark>
</TradeMarkDetails>
</TransactionData>
</TransactionContentDetails>
</TradeMarkTransactionBody>
</Transaction>
I would like to be able to produce:
App number: 74631225
Here are a couple of my failed attempts; Attempt #1:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/">
App number: <xsl:value-of select="/Transaction/TradeMarkTransactionBody/TransactionContentDetails/TransactionData/TradeMarkDetails/TradeMark/ApplicationNumber"/>
</xsl:template>
</xsl:stylesheet>
Produces only:
App number:
Attempt #2:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/Transaction/TradeMarkTransactionBody/TransactionContentDetails/TransactionData/TradeMarkDetails/TradeMark">
App number: <xsl:value-of select="ApplicationNumber"/>
</xsl:template>
</xsl:stylesheet>
produces:
National Trademark Information
US
74631225
1995-02-07-05:00
2178784
1998-08-04-04:00
US
2008-08-11-04:00
JAVA
Any help would be appreciated. Once I get past this gate and have at least one field working, I hope I can get into the real substance of my project. If it matters, I'm using both MSXSL and Treebeard (which uses Saxon, I think) for my testing.
Your XSLT code is missing the namespace declaration. Check out the root element in your Xml document, it says this:
xmlns="http://www.wipo.int/standards/XMLSchema/trademarks"
That means, any of the elements in your Xml document are in that namespace.
In the XSLTs, on the other hand, you did not specify any namespace, which means that your XSLT processor looks for element names specified in the XSLT with the "blank namespace" - so e.g. Transaction mentioned in your XSLT is not the same element as Transaction (from the http://www.wipo.int/standards/XMLSchema/trademarks namespace) mentioned in your Xml document.
XSLT, or rather XPath, does not know the concept of a "default" (prefix-less) namespace, which is why you will have to assign some arbitrary prefix - say tm:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tm="http://www.wipo.int/standards/XMLSchema/trademarks">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/">
App number: <xsl:value-of select="/tm:Transaction/tm:TradeMarkTransactionBody/tm:TransactionContentDetails/tm:TransactionData/tm:TradeMarkDetails/tm:TradeMark/tm:ApplicationNumber"/>
</xsl:template>
</xsl:stylesheet>
This should get you a step closer to what you are looking for. I can try this only in a few hours from now; if you need further assistance, please leave a comment and I'll check back on this question.
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.