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.
Related
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.
I've created an XSLT stylesheet document. Within this document I create a new XML document as stated below:
...
<CREATE_REQ
xsi:schemaLocation="http://fcubs.ofss.com/service/aServices theService.xsd"
xmlns="http://fcubs.ofss.com/service/aServices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
After transformation (see below) the ordering of the namespaces is different. A normal XML parser can handle this and it is normally no problem. The problem in my case is that the receiving application can't handle this and the order of the namespace may and shouldn't be changed.
<CREATE_REQ xmlns="http://fcubs.ofss.com/service/aServices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://fcubs.ofss.com/service/aServices theService.xsd">
...
Is there a function or declaration that the namespaces will not be changed?
If the receiving application can't handle it then it needs to be fixed. Whoever wrote it doesn't seem to have grasped what XML is all about. Fix the receiving application, or throw it in the bin where it belongs.
After transformation (see below) the ordering of the namespaces is
different.
No, the ordering is exactly the same. According to the W3C XPath 1.0 Data Model:
The attribute nodes and namespace nodes of an element occur before the children of the element. The namespace nodes are defined to occur before the attribute nodes.
This means that although in the provided XML fragment the attribute xmlns:xsi seems to precede the namespace declarations, in fact it follows them.
Therefore, the produced output doesn't change the ordering of namespaces and attributes of the original XML document.
Producing an XML document where an attribute precedes a namespace node would violate the above quoted definition, therefore a compliant XSLT processor wouldn't produce such a document.
What does a namespace do in XSLT when a url is provided such as:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
does this attempt to make a connection to the internet?
No; it just so happens that the specification for XML Namespaces (see W3C XSL Namespace specifications) are URI's.
They work in exactly the same way that namespaces in other languages do; they help uniquely identify things with the same names but in different contexts.
You can prove that no attempt is made to retrieve the resource by using a HTTP Monitor on your machine while loading or using the XSL Transformation - this answer has many good suggestions.
No.
Whatever the namespace is in a xsd, an xslt or any other xml file, there is no internet request.
The namespace is used to qualified your xml element.
When you conduct an XSLT transformation, the XSLT engine validates the XSLT file. It performs many checks, such as the root element being named stylesheet, etc. The engine must also be able to discern literal result elements (like <table>) from XSLT-specific elements (like <xsl:stylesheet>).
An element is recognized as XSLT-specific when it resides in the XSLT namespace. The value of the URI you posted (http://www.w3.org/1999/XSL/Transform) is simply a convention that makes it clear we're talking about XSLT. The prefix being defined (xsl) is the prefix used in the XSLT file to qualify the XSLT elements. You can use another prefix if you choose, provided you map it to the XSLT namespace.
Note that it's actually just a URI (an identifier), not a URL (a locator). There is no HTTP request to locate anything, it just identifies an abstract concept (in this case "XSLT").
I just added a namespace to my XML document and now my XSLT stylesheet does not work. What do I have to change in XSLT to support namespaces? (I have not yet changed the XSLT file since adding namespaces)
You have to add a xmlns:namespacehere attribute and use the namespace in the appropriate matches and selections.
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.