xsl-list
[Top] [All Lists]

Re: [xsl] Avoiding boneheaded mistakes in XSLT?

2010-12-30 02:59:10
On Wed, 29 Dec 2010 23:36:35 +0000
Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:


Even without schema awareness/context, surely the processor can
tell when an xpath expression will result in zero match?


No, it's very rarely possible.

For example, consider

<xsl:template match="books">
<xsl:value-of select="book[1]/authour"/>
</xsl:template>

Even if you have a schema telling you that the children of books can 
include book but the children of book can't include authour, this 
doesn't tell you that this path will necessarily return nothing - 
because there is no way you can know that every books element that
the stylesheet processes will be valid against this schema.

Still ignoring schema.
My supposition is that *for the xml instance being processed*
either the expression will or will not return a non-empty
sequence. Hence there is a possible error.
In this case either the first book child has an author child or not.
Surely that information is available Mike?



In fact it's quite common for a stylesheet to create intermediate 
results that (deliberately) aren't valid against the schema for the 
input or output document.

Again, I'm not considering the impact of a schema. Separable issue
likely better reporting. 



It would however be possible to make a guess that this is wrong, and 
issue a warning. Incorrect warnings are always very irritating, so
this is not something to be done lightly, but it's something I've
wanted to attempt for a long time.


DC made a couple of Minority IMHO examples where the reporting would
or could be a nuisance. The best example being a docbook instance, 
where 1001 templates won't match, and Schematron where the test if
for an empty sequence. 

Accepting that, and schema based transforms, perhaps the sensible option
would be to have this as a 'default off' function? Clearly a warning is
the best that could be emitted. 




-- 

regards 

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--