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.
Related
This is my first question here so please don't beat me up to hard :)
I am using Apache Camel with Saxon XSLT transformer. And my goal is to output the results of an XSLT transformation into a file. I searched a lot but could not find any hints as to why I am getting that error.
This is my XSLT snippet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:core="http://interoperability.gc.ca/core/1.0"
exclude-result-prefixes="xs xsi xsl">
<xsl:output method="text" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:variable name="someE">
<someE>
<someA>aaaa</someA>
<someB>bbbb</someB>
</someE>
</xsl:variable>
<xsl:result-document href="transformer.out" method="text" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:copy-of select="$someE"/>
<xsl:result-document/>
</xsl:template>
</xsl:stylesheet>
where $destinationAbsolutePath is the absolute file path (file:///C:/Temp/output.txt) of the output file.
What am I missing ?
Update:
I ran the transformation from the command line and got the same failure:
C:\Temp\osfsa>java -jar Saxon-HE-9.9.1-7.jar -t -o:C:\Temp\osfsa\out\index.out -s:C:\Temp\osfsa\in\exporter.out -xsl:C:\Temp\osfsa\xml2fixedlength.xsl
Saxon-HE 9.9.1.7J from Saxonica
Java version 11.0.13
Stylesheet compilation time: 1.1386491s (1138.6491ms)
Processing file:/C:/Temp/osfsa/in/exporter.out
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Building tree for file:/C:/Temp/osfsa/in/exporter.out using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 12.0011ms
Tree size: 62 nodes, 157 characters, 9 attributes
Writing to file:/C:/Temp/osfsa/out/transformer.out
Error in xsl:result-document/#href on line 18 column 112 of xml2fixedlength.xsl:
XTDE1490: Cannot use xsl:result-document to write to a destination already used for the
principal output: file:/C:/Temp/osfsa/xml2fixedlength.xsl
In template rule with match="/" on line 11 of xml2fixedlength.xsl
Cannot use xsl:result-document to write to a destination already used for the principal output: file:/C:/Temp/osfsa/xml2fixedlength.xsl
You've obviously simplified your code for demonstration purposes (we can tell because it's not well-formed, and because the error message refers to line 27), which is fine in principle, except that I think you've removed something critical to the error.
Here's an example that will give you the error. If you run a transformation with file:///out.xml as the principal output destination (specified when the transformation is invoked), and the transformation then does:
<xsl:template match="/">
xxx
<xsl:result-document href="file:///out.xml">
yyy
</xsl:result-document>
</xsl:template>
then you will get this error. The key ingredients are
(a) the href value on xsl:result-document is the same URI (after absolutisation) as the principal output URI
(b) some output has already been written ('xxx' in this example) when xsl:result-document is evaluated.
I hope this helps you resolve it. If not, you need to give us more details of exactly what you are running and how.
Update
There's something a little bit strange here, which is that the URI appearing in the error message is the URI of the stylesheet; I would expect it to be the output URI. That might just be poor diagnostics, I will check.
Further Update
Your code contains two xsl:result-document instructions, both empty:
<xsl:result-document href="transformer.out" method="text" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:copy-of select="$someE"/>
<xsl:result-document/>
You presumably intended to write a single instruction, with xsl:copy-of as its content:
<xsl:result-document href="transformer.out" method="text" omit-xml-declaration="yes" encoding="utf-8">
<xsl:copy-of select="$someE"/>
</xsl:result-document>
The second xsl:result-document instruction has no #href attribute, so it defaults to writing to the principal output; but the xsl:copy-of instruction has already written to the principal output.
Now I need to understand why the wrong URI appears in the error message.
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.
this is an empty xml document for which i am generating a response
<?xml version="1.0"?>
<EmptyResult xmlns="http://www.tandberg.com/XML/CUIL/2.0" product="TANDBERG Codec" version="TC7.1.1.168aadf" apiVersion="2"/>
this is the code for response
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="//objects"/>
</xsl:template>
<xsl:template match="objects">
</xsl:template>
</xsl:stylesheet>
Your problem isn't directly XSLT related, but a question of your XSLT processor. Depending on what you use (Java, .net, PHP, Ruby etc.) you get different error messages when your output doesn't yield a result.
There are several steps you can take:
handle the error in your code. After all your stylesheet doesn't do its job
fix the stylesheet to include an output for an <EmptyResult tag too
While you are on it: select=// is a performance killer for large outputs
Hope that helps
I am new to xslt. When i am using below piece of code for transformation from one form to another. is this below format correct?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:app="http://*/*/*/applicationRequest">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/app:ApplicationRequest/BusinessChannel">
<xsl:copy-of select="$ApplicationBatchDocument/BusinessChannel"/>
</xsl:template>
</xsl:stylesheet>
is this below format correct?
Short answer:
No. You are using an undefined variable $ApplicationBatchDocument.
Longer answer:
XSLT transforms an XML document from one schema for to another. If you don't show us what the input document looks like, and what do you want the output to look like, then no good answers are possible.
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