XSLT Illegal attribute 'separator' - xslt

Aloha,
while writing an XSLT stylesheet, I encountered a problem, I could not solve. My basic XML structure is the following
<nonUniqueConstraint name = "...">
<column name = "..."/>
<column name = "..."/>
</nonUniqueConstraint>
I want to print the names of all columns. Therefore I used the following statement (I'm iterating over all nonUniqueConstraints):
<xsl:value-of select="./column/#name" separator=", "/>
However when I run my Ant build file, it outputs the following:
Error! [ERR 0510][ERR XTSE0090] The illegal atttribute 'separator' is
specified
I looked for the error and found the following description:
[ERR XTSE0090] It is a static error for an element from the XSLT
namespace to have an attribute whose namespace is either null (that
is, an attribute with an unprefixed name) or the XSLT namespace, other
than attributes defined for the element in this document.
Nevertheless I have seen many examples using the separator attribute, e.g. here.
How can I fix that problem?
Cheers

Look at stylesheet element on version attribute - it should be 2.0 to enable attribute "separator" at xsl:value-of
<xsl:stylesheet version="2.0"...

I think you should check which XSLT processor you are running.
The error is a little odd, because the error code XTSE0090 is defined only in XSLT 2.0, yet XSLT 2.0 permits the separator attribute. Jirka's reply is only partially correct. If you are running an XSLT 1.0 processor, it will always reject the separator attribute, but it is unlikely to use the XSLT 2.0 error code XTSE0090. If you are running a 2.0 processor, it should accept the separator attribute whether the stylesheet specifies version="1.0" or version="2.0". So there's something a bit strange going on.
To check what XSLT processor you are using, use the XSLT system-property() function to write a message.

Related

Generate Schematron "see" attribute value

I would like to dynamically generate the Schematron see attribute based on the the user home's directory. I could not get this working. Do you have an idea if this is possible? It needs to work in Oxygen XML. I am not sure if this is technically not possible in Schematron, or if this is a bug in Oxygen XML.
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
<sch:pattern>
<sch:rule context="/">
<sch:let name="x" value="if (contains(base-uri(), 'myname'))
then 'http://www.a.com'
else 'http://www.b.com'"/>
<sch:report test="'a' = 'a'">
Hello world: "<sch:value-of select="$x"/>"
</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
My goal is to generate a user-specific link to a locally deployed style guide, but, as you can see in the screenshot, the variable x is not resolved.
Maybe you can try to read the “user.home” system property: https://www.saxonica.com/html/documentation12/functions/fn/system-property.html
Using Schxslt it seems the syntax of an XSLT attribute value template in the form of e.g. see="{$x}" in Schematron then generates an SVRL report having the URI in the form of e.g.
<svrl:successful-report location="/" see="http://www.b.com" test="'a' = 'a'">
<svrl:text>
Hello world
</svrl:text>
</svrl:successful-report>
I don't know whether oXygen has any integration for Schxslt as a Schematron validator and for rendering the validation result in the form of SVRL.
To build on the answer by #radu-coravu, you might be able to get the 'user.home' value by using a function in an external XSLT file:
Use xsl:include in your Schematron file to include the XSLT. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L23
Write a function in the external XSLT that returns the "user.home" system property value
In your rule in your Schematron, use let to get the return value of the function as a variable value. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L31
Use the Schematron variable in your assert and report just like any other variable

Invalid attribute name xmlns:xsl1 while validation XSL in Saxon XSLT parser

We have been using Xalan for XSL transformations for quiet a while and recently moved over to Saxon for XSL transformation.Currently I am using Saxon PE (9.5 version) for XSL transformations 1.0 version (Backward Compatibility mode). Although I am facing difficulties while validating a XSL which came up to me contains a attribute named as shown below.
<xsl:attribute name="xmlns:xsl1">
<xsl:value-of select="check"/>
</xsl:attribute>
While validating the XSL i get the error "Error message: Invalid attribute name: {xmlns:xsl1}" although the same validates in Xalan .
Now my question is the name of the attribute valid in this case . Please explain ??
It's not a valid attribute name. xmlns is a reserved prefix that is used for specifying namespace declarations.
It violates this rule in the XSLT 2.0 specification:
[ERR XTDE0860] In the case of an xsl:attribute instruction with no namespace attribute, it is a non-recoverable dynamic error if the effective value of the name attribute is a lexical QName whose prefix is not declared in an in-scope namespace declaration for the xsl:attribute instruction.
(Careful reading of the data model reveals that "xmlns" is not declared in an in-scope namespace declaration, although "xml" is.)
More pertinently, you can't use xsl:attribute to create a namespace declaration: you need to use xsl:namespace for this purpose.
Xalan is following the rules in XSLT 1.0. This is less explicit that this case is an error, but it does say "If the namespace attribute is not present, then the QName is expanded into an expanded-name using the namespace declarations in effect for the xsl:attribute element, not including any default namespace declaration." which in my view carries the implication that if the prefix is not declared, an error results.

The xsl:variable element must not have both content and a select attribute

I am wondering what this documentation:
If the select attribute is present, the element cannot contain any content
about the xsl:variable element at:
[1]: http://www.w3schools.com/xsl/el_variable.asp%20w3%20schools means?
The reason I ask is because I am encountering this error:
JAXPSAXProcessorInvoker - java.lang.RuntimeException: ElemTemplateElement error: The xsl:variable element must not have both content and a select attribute. during transformation. Weird thing is it "runs" with the eclipse default processor but not xalan.
When it runs with the eclipse default processor, I find that some of the elements in the original document I am converting do not show up in the result document, I am curious if it is related to this. and the eclipse processor just masks the issue while the xalan processor fails.
I believe this is the offending line:
<xsl:variable name="vSections" select="//*[local-name()='ItemDef']/*/*/*[local-name()='SectionLabel'][generate-id() = generate-id(key('kLabelsInForm', concat($vFormOID, '+', .))[1])]">
<xsl:value-of select="concat(., ' ')" />
</xsl:variable>
Thanks for the explanation.
This rule is present in both XSLT 1.0 and in 2.0. If you have a stylesheet that contains this error and you find a processor that does not report the error, that's a bug (non-conformance) in the processor. It's not a bug you need to worry about much, just fix the error in your stylesheet.

How to use an expression in xsl:include element in an XSLT processing

I need to include an XSLT that exists in 2 variants, depending on a param value.
However, it's seems to be not possible to write an expression in the href attribute of the xsl:include element. My last trial looks like that:
< xsl:param name="ml-fmt" select="mono"/>
...
< xsl:include href="{$ml-fmt}/format.xsl"/>
The XSLT engine used is Saxon 9.2.0.6
Have anybody an idea about how I could do something close to that ?
As Dimitre has said you can't do it, but you can generate the XSLT file from scratch or slightly modify an existing XSLT file by inserting the node in the code preparing the transformation.
You can't.
If you know all possible xslt stylesheet modules to be included, you could use the xsl:use-when attribute in order to selectively include only some of them. However, xsl:use-when has its own limitations. To quote the XSLT 2.0 Spec:
"Any element in the XSLT namespace may have a use-when attribute whose value is an XPath expression that can be evaluated statically".
There is a way to achieve dynamic inclusion, but it requires some non-XSLT initialization:
The code (think C# or Java or ... your programming language) that invokes the transformation, can edit the DOM of the loaded (as XML) XSLT stylesheet and can set the value of the href attribute of any <xsl:import> element to the desired URL.

Get file name using xsl

How can I get the file name using xsl 1.0?
I tried
<xsl:value-of select="base-uri()" />
but got "Fatal Error! Could not find function: base-uri"
base-uri() is a standard XPath 2.0 function, so when running XSLT 1.0 this function will be unavailable.
In XSLT 1.0 the filename (of what?) may be passed as a parameter for the transformation.
Do note that it isn't always possible to produce a filename for a stylesheet or for an XML document -- either or both may be residing in memory without an associated file.
It is not clear from the problem which filename must be produced.
Here is how to find filenames in XPath 2.0 / XSLT 2.0:
The filename of the current document:
base-uri()
The filename of the current stylesheet module:
base-uri(document(''))
There is no such XPath function, or XSLT extension to XPath function to do this in XSLT v1/XPath v1.
It is quite possible for there to be no file, and even if there is no reason for the XSLT engine to have that file name (consider loading the file content into a buffer, parsing the buffer into a DOM and then passing the DOM to the XSLT processor).
You will need to pass the filename into the processor to be available as a parameter in the transform.