Re: [xsl] Avoiding boneheaded mistakes in XSLT?

Subject: Re: [xsl] Avoiding boneheaded mistakes in XSLT?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Dec 2010 10:07:26 -0500
At 2010-12-29 14:54 +0000, Dave Pawson wrote:
On Wed, 29 Dec 2010 09:45:53 -0500
"G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:

> At 2010-12-29 14:39 +0000, Dave Pawson wrote:

> >Even without schema awareness/context, surely the processor can
> >tell when an xpath expression will result in zero match?
>
> But it isn't helpful because the zero match is ambiguously either the
> result of a typo in the stylesheet or the absence of an acceptable
> item in the source.  The processor is obliged to assume the latter
> and so cannot assume the former.

But it is Ken. It's somewhere to look when the author wants to
debug 'the pair'? Stylesheet and source XML.

Forgive me, Dave, for not successfully conveying to you what I'm trying to say. Allow me to try again, please.


Consider an XML document whose content model for <a> is: ( b, c?, d )

This is a valid instance:

  <a>
    <b/>
    <c/>
    <d/>
  </a>

But, this is also a valid instance:

  <a>
    <b/>
    <d/>
  </a>

So, given the second instance, I run it against two stylesheets:

Stylesheet 1:

<xsl:if test="not(a/c)">I'll make an assumption about a missing C</xsl:if>

Stylesheet 2 (with a typo in it because the user mistyped):

<xsl:if test="not(a/cc)">I'll make an assumption about a missing C</xsl:if>

Without a schema to know that <cc> is not an acceptable element, there is no way to distinguish the two above if statements. With a schema, the second one is clearly in error. But without a schema, it does not make sense to issue an error or warning about the first stylesheet, because it is a bona fide test I want to perform regarding the absence of <c>. Hence, it cannot make the same assumption about the second stylesheet, and so again cannot issue an error or warning.

Now, consider UBL 2.1 with 2,000 elements, 1,800 of which are optional. Looking at address:

http://docs.oasis-open.org/ubl/prd1-UBL-2.1/mod/summary/reports/UBL-AllDocuments-2.1.html#t-CommonLibrary-14

... that one element has 25 optional children. If I process a UBL instance without a schema, and I check for any of the 25 optional children that happen to be absent from my instance, your suggestion is I would get an error or a warning for every access to that element that is not in the source file. But they are allowed not to be in the source file. I should be allowed to test their absence.

For me to know that <cbc:CitySubDivisionName> is *incorrect* and that <cbc:CitySubdivisionName> *is* correct is up to a schema-aware processor, with schema-awareness turned on, and me supplying the UBL schema to tell me that I've typed that element name incorrectly. Without all of those conditions, the processor is obliged to say "that's okay, you just don't have any <cbc:CitySubDivisionName> elements in your document, so continue on as you were" even if the instance has <cbc:CitySubdivisionName> correctly in the document.

I hope this helps this time around!

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread