Saxon can't find package - saxon

I encounter some difficulties when using packages with Saxon 9.8. Saxon can't find the package I want to use and fail at compilation.
When using the -lib option from the command line, I get the following error message:
java.lang.NullPointerException
at net.sf.saxon.style.PackageVersion.<init>(PackageVersion.java:71)
at net.sf.saxon.trans.packages.VersionedPackageName.<init>(VersionedPackageName.java:29)
at net.sf.saxon.trans.packages.PackageInspector.getNameAndVersion(PackageInspector.java:78)
at et.sf.saxon.trans.packages.PackageInspector.getPackageDetails(PackageInspector.java:91)
at net.sf.saxon.trans.packages.PackageLibrary.<init>(PackageLibrary.java:96)
at net.sf.saxon.Transform.doTransform(Transform.java:404)
at net.sf.saxon.Transform.main(Transform.java:81) Fatal error during transformation: java.lang.NullPointerException: (no message)
When using -lib option in oXygen 19 with the Saxon 9.8 add-on, I get the following message:
Nom du moteur: Saxon-EE 9.8.0.4 (External)
Gravité: fatal
Description: Cannot find package img_pkg (version *)
Emplacement de début: 7:52
I get exactly the same error message in oXygen when I use a configuration file to declare the package.
I'm pretty sure that there is no problem with the file path. Since in the error message I get in oXygen the package version doesn't seem to be recognized, I thought it could be a syntax problem but I can't find where it comes from.
Here is test my package:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:package name="img_pkg" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:img="https://www.ephe.fr/annuaire/colin-brisson"
exclude-result-prefixes="xs img" version="1.0">
<xsl:function name="img:test" visibility="final" as="xs:string">
<xsl:value-of select="'test ok'"/>
</xsl:function>
</xsl:package>
Here's my test sylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:img="https://www.ephe.fr/annuaire/colin-brisson" exclude-result-prefixes="xs"
version="3.0">
<xsl:use-package version="1.0" name="img_pkg"/>
<xsl:template name="xsl:initial-template">
<xsl:message>
<xsl:value-of select="img:test()"/>
</xsl:message>
</xsl:template>
</xsl:stylesheet>
Many thanks in advance!

I think that the NullPointerException from the command line is due to bug 3373
https://saxonica.plan.io/issues/3373
although in your case the root cause is a little different from that in the bug entry, it's the absence of a package-version attribute. This is fixed in 9.8.0.4, but from the line numbers in the stack trace it looks to me as if you are using an earlier maintenance release.
The problem in oXygen is probably completely different, but it might again be related to the absence of #package-version.

Related

Getting errors in Saxon-HE 9.9.1 when processing DITA: I/O error on DTD

Using Saxon 9.9.1.3J, I am getting an I/O error every time I try to transform a DITA file that has a DTD:
I/O error reported by XML parser processing file:/test.dita: /learningAssessment.dtd (No such file or directory)
This happens even if I force -dtd:off on the command line. Commenting out the DTD in the DITA file does allow it to process.
Interestingly, when I run the same DITA file in oXygen using Saxon-HE 9.8.0.12, it does process correctly. Any idea what might be causing this to behave differently?
Sample DITA file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE learningAssessment PUBLIC "-//OASIS//DTD DITA Learning Assessment//EN" "learningAssessment.dtd">
<learningAssessment id="id">
<title>Title</title>
<learningAssessmentbody>
<lcInteraction>
<lcSingleSelect id="lcSingleSelect_agy_fxz_ljb">
<lcQuestion>Question</lcQuestion>
<lcAnswerOptionGroup id="lcAnswerOptionGroup_bgy_fxz_ljb">
<lcAnswerOption>
<lcAnswerContent>A</lcAnswerContent>
</lcAnswerOption>
<lcAnswerOption>
<lcAnswerContent>B</lcAnswerContent>
<lcCorrectResponse/>
</lcAnswerOption>
</lcAnswerOptionGroup>
</lcSingleSelect>
</lcInteraction>
</learningAssessmentbody>
</learningAssessment>
And here's a shell of an XSL that demonstrates the error:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output />
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
You can resolve the problem by the following steps:
Download DITA-OT and expand it any folder you like. In my case it is located at D:\DITA-OT\dita-ot-3.3.4.
Set CLASSPATH environment variable to contain saxon9he.jarand xml-resolver-1.2.jar in DITA-OT/lib.
Invoke Saxon by specifying class name net.sf.saxon.Transform and the catalog: paramter that specifies [DITA-OT]/catalog-dita.xml.
Here is execution example command window:
Hope this helps!
My guess is that you have somehow contrived to give the document a base URI of "file:/test.dita: ", including the final space. You haven't shown how you are running the transformation, so we can't tell where this base URI comes from.
The option -dtd:off is a little misleading. It doesn't switch off DTD processing, only DTD-based validation, which is just one aspect of DTD processing. An XSLT processor always needs to ask the XML parser to read the DTD in order to expand any entity references.
(Well, theoretically it could delay reading any external DTD until it finds the first entity reference; but sadly, I don't know of any XML parser that does that.)
I misunderstood how DTDs work. I assumed the public ones were loaded from an HTTP URL, but they need to be local files. Loading the catalog for DITA OT resolved the issue.
transform -s:test.dita -xsl:test.xsl -o:test.html -catalog:/org.oasis-open.dita.v1_2/plugins/org.oasis-open.dita.v1_2/catalog.xml
Where the catalog option points to this file on my local filesystem, which comes from DITA OT

Debug <?xml-stylesheet type="text/xsl" href="#test"?> in oXygen

I am writing test files that test functionality of an XSLT library. For this, I embed tiny XSLTs in the XML file itself so that I don't need a separate XML and XSLT file for each test. This looks somewhat like this:
<?xml-stylesheet type="text/xsl" href="#test"?>
<someXml xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<test feature="lib:someFeature(...)">
<xsl:stylesheet version="2.0" xml:id="test">
<xsl:import href="../testlib.xsl"/>
<xsl:template match="*[lib:assertRef(#label, lib:someFeature())]" mode="assert"/>
</xsl:stylesheet>
</test>
<someContent label="assert: #someId"/>
<someMoreContent xml:id="someId"/>
</someXml>
Is there a way in oXygen to debug this? Does oXygen have a way to run transformations based on the <?xml-stylesheet?> rules at all? Usually, this is not much of a problem as the referenced stylesheet can be run explicitly, but when the stylesheet is embedded, it's something different.
As confirmed by oXygen developer #RaduCoravu, this is not possible at the moment.

XPath syntax error thrown when using evaluate() method

Still i am getting the below error
Error at xsl:param on line 6 of file:/E:/saxon/parastyleText.xsl:
XPST0003: XPath syntax error at char 0 on line 6 in {...le/#w:val[matches(., c
oncat...}:
Invalid character '^' in expression
Failed to compile stylesheet. 1 error detected.
Modified XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
<xsl:param name="styleName" select="'articletitle'"/>
<xsl:param name="tagName" select="'//w:p[w:pPr/w:pStyle/#w:val[matches(., concat('^(',$styleName,')$'),'i')]]'"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="saxon:evaluate($tagName)" xmlns:saxon="http://saxon.sf.net/"/><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
Please dont reply that, quotes will make 'tagName' as string and remove those quotes. This value will be actually passed from java as a string , tats y for testing purpose i have passed this xpath as string.
According to the online documentation http://www.saxonica.com/documentation9.1/extensions/functions.html Saxon 9.1 supports an evaluate function in the Saxon namespace http://saxon.sf.net/. So with Saxon 9.1 try <xsl:value-of select="saxon:evaluate($tagName)" xmlns:saxon="http://saxon.sf.net/"/>. Of course you can move the namespace declaration up to the xsl:stylesheet element if you want, I just put it on the xsl:value-of in this post for a short but complete sample of code.
Also note that with your variable named tagName it is likely that you simply have a single element name, in that case it might suffice to use <xsl:value-of select="*[local-name() eq $tagName]"/>.

How can I get xslt to indent xml (from Ant)?

From what I understand having looked around for an answer to this the following should work:
<xslt basedir="..." destdir="..." style="xslt-stylesheet.xsd" extension=".xml"/>
Where xslt-stylesheet.xsd contains the following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Unfortunately while most formatting is applied (spaces are stripped, newlines entered, etc.), indentation is not and every element is along the left side in the file. Is this an issue with the xslt processor Ant uses, or am I doing something wrong? (Using Ant 1.8.2).
It might help to set some processor-specific output options, though you should note that these may vary depending on the XSLT processor that you're using.
For example, if you're using Xalan, it defines an indent-amount property, which seems to default to 0.
To override this property at runtime, you can declare xalan namespace in your stylesheet and override using the processor-specific attribute indent-amount in your output element as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan">
<xsl:output method="xml"
encoding="UTF-8"
indent="yes"
xalan:indent-amount="2"/>
This example is from the Xalan usage patterns documentation at http://xml.apache.org/xalan-j/usagepatterns.html
If you do happen to be using Xalan, the documentation also says you can change all of the output preferences globally by setting changing the file org/apache/serializer/output_xml.properties in the serializer jar.
In the interest of completeness, the complete set of Xalan-specific xml output properties defined in that file (Xalan 2.7.1) are:
{http://xml.apache.org/xalan}indent-amount=0
{http://xml.apache.org/xalan}content-handler=org.apache.xml.serializer.ToXMLStream
{http://xml.apache.org/xalan}entities=org/apache/xml/serializer/XMLEntities
If you're not using Xalan, you might have some luck looking for some processor-specific output properties in the documentation for your XSLT processor
Different XSLT processors implement indent="yes" in different way. Some indent properly, while others only put the element starting on a new line. It seems that your XSLT processor is among the latter group.
Why is this so?
The reason is that the W3C XSLT Specification allows significant leeway in what indentation could be produced:
"If the indent attribute has the value yes, then the xml output
method may output whitespace in addition to the whitespace in the
result tree (possibly based on whitespace stripped from either the
source document or the stylesheet) in order to indent the result
nicely; if the indent attribute has the value no, it should not
output any additional whitespace. The default value is no. The xml
output method should use an algorithm to output additional whitespace
that ensures that the result if whitespace were to be stripped from
the output using the process described in [3.4 Whitespace Stripping]
with the set of whitespace-preserving elements consisting of just
xsl:text would be the same when additional whitespace is output as
when additional whitespace is not output.
NOTE:It is usually not safe to use indent="yes" with document types that include element types with mixed content."
Possible solutions:
Start using another XSLT processor. For example, Saxon indents quite well.
Remove the <xsl:strip-space elements="*"/> directive. If there are whitespace-only text nodes in the source XML, they would be copied to the output and this may result in a better-looking indented output.
I don't know if ant is OK. But concerning your XSLT :
When you use the copy-of on an element, your XSLT processor does not indent. If you change your XSLT like this, your XSLT processor will may be manage to indent :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This XSLT will go through the whole XML tree and indents each element it creates.
EDIT after comment :
You can see the following question to change your XSLT processor, maybe it will solve your problem : How to execute XSLT 2.0 with ant?
You can try adding the {http://xml.apache.org/xslt}indent-amount output property in ant, something like this:
<target name="applyXsl">
<xslt in="${inputFile}" out="${outputFile}" extension=".html" style="${xslFile}" force="true">
<outputproperty name="indent" value="yes"/>
<outputproperty name="{http://xml.apache.org/xslt}indent-amount" value="4"/>
</xslt>
</target>

How to Use DataSource Property in DataFormWebPart

I'm writing a custom web part that extends DataFormWebPart.
public class MyCustomWebPart : DataFormWebPart{
// other methods
public override void DataBind()
{
XmlDataSource source =
new XmlDataSource() { Data = #"
<Person>
<name cap='true'>Bryan</name>
<occupation>student</occupation>
</Person>
"
};
DataSources.Add(source);
base.DataBind();
}
}
The only noticeable thing I do is overriding the DataBind() method, where I use xml as the data source.
After I deploy the web part, I set the following XSL to it:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp>
<xsl:copy-of select="*"/>
</xmp>
</xsl:template>
</xsl:stylesheet>
This xsl will surround the input xml with a tag . So I expected the web part to display the original xml data as I wrote in C# code behind. But what shows up in the web part is this:
<Person>
<name cap="true" />
<occupation />
</Person>
All the values within the inner-most tags disappear.
What's going on? Can anybody help me?
Thanks.
I know this is several months since your question but I also experienced this same issue and have found the resolution.
On this MSDN forum post - http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/0a0527b6-3a05-4791-8cc5-9a6de07d23f3
they mentioned that there is a bug in the xsmldatasource xpath navigation binding, and the resolution is to override the GetXPathNavigator method.
moving code from the databind to this method immediately resolved the lookup issue.

Resources