XSLT Validation in Editor

Are you missing a feature? Request its implementation here.
kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

XSLT Validation in Editor

Post by kruncher »

Hi,

I have recently experienced a serious problem with one of my stylesheets which could have been eased if the XSLT validation in the <oxygen/> editor raised the following as an error:

<xsl:template match="something">
<!-- AVTs cannot be used for "xml:base" attribute! -->
<something-else xml:base="{my:get-prefix(.)}"/>
</xsl:template>

The "xml:base" attribute forms a part of the stylesheet itself, and as such much be well formed. An AVT, therefore, is an invalid URI. I think that there should be a note indicating that "xsl:attribute" should be used for those who are learning XSLT.

Note to learners: The following is how it should be done!

<xsl:template match="something">
<!-- AVTs cannot be used for "xml:base" attribute! -->
<something-else>
<xsl:attribute name="xml:base" select="my:get-prefix(.)"/>
</something-else>
</xsl:template>

Just an idea,
Lea Hayes
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: XSLT Validation in Editor

Post by sorin_ristache »

Hello,
kruncher wrote:The "xml:base" attribute forms a part of the stylesheet itself, and as such much be well formed. An AVT, therefore, is an invalid URI. I think that there should be a note indicating that "xsl:attribute" should be used for those who are learning XSLT.
I think your template does not conain a validation error and an AVT can be used in the value of an xml:base attribute. The value of the xml:base attribute does not have to be a full valid URI. There is no specification that requires that. For example it is allowed to be a relative path.

If you want to be sure that the value of the xml:base attribute in the output of the transformation contains a valid URI you can enforce that with an XML Schema for the output and using Saxon SA as transformer which is able to validate the output of the transformation against a specified XML Schema.


Regards,
Sorin
kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

Re: XSLT Validation in Editor

Post by kruncher »

> There is no specification that requires that.

Surely "xml:base" must validate with "xs:anyURI"?

It was actually Michael Kay (author of Saxon) who told me it was invalid to have an AVT in a "xml:base" attribute. And it certainly makes sense, because the "xml:base" attribute contributes towards the stylesheet and not just the output.

When using Saxon, if an AVT is used for the "xml:base" it actually causes some bad stuff to occur. For example, an error message gets thrown by an otherwise valid stylesheet, and some other corruption occurs.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XSLT Validation in Editor

Post by george »

You are right, the xml:base needs to have a correct value also in the stylesheet as it contributes to the base URI of the stylesheet elements. FWIW the relevant part of the XSLT specification can be found in the note below:
http://www.w3.org/TR/xslt20/#attributes-for-lres
Note:

The xml:base, xml:lang, xml:space, and xml:id attributes have two effects in XSLT. They behave as standard XSLT attributes, which means for example that if they appear on a literal result element, they will be copied to the result tree in the same way as any other attribute. In addition, they have their standard meaning as defined in the core XML specifications. Thus, an xml:base attribute in the stylesheet affects the base URI of the element on which it appears, and an xml:space attribute affects the interpretation of whitespace text nodes within that element. One consequence of this is that it is inadvisable to write these attributes as attribute value templates: although an XSLT processor will understand this notation, the XML parser will not.
Best Regards,
George
George Cristian Bina
Post Reply