xsl-list
[Top] [All Lists]

Re: Re: The Perils of Sudden Type-Safety in XSLT 2.0

2003-02-27 08:10:56
Hi Kurt:

Yeah, I suggested a type safety switch as well mid way through the thread,
and I think Mike Kay responded it was one of the things the WG was looking
at. I brought up the versioning thing only as a reminder that this is where
things currently stand -- that there is at least a way out of data typing if
you wish, albeit a strange one. The weird part about it is that it will lead
to an awful lot of questions on this list, with subsequent screams,
eventually, of, "This is an FAQ!" The question of course will be centered
around why version 2 elements are readable in documents with version 1
assigned to the stylesheet elements. I personally don't really care that
much. But there can't be much doubt that confusion and lots of questions
will result.

I understand the concession to Microsoft argument, but it is a reality that
Microsoft has an installed based that needs to be considered, politics
aside. To me, igoring them would be like ignoring Netscape in the early days
when they introduced the FRAME element and the W3C added it to the HTML rec.
A lot of people didn't like it, but sometimes reality forces us to shrug our
shoulders. I don't get the impression you care that much either -- I'm just
sort of raising the point generally.

~ Chuck White

----- Original Message -----
From: "Kurt Cagle" <kurt(_at_)kurtcagle(_dot_)net>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Thursday, February 27, 2003 12:42 AM
Subject: Re: [xsl] Re: The Perils of Sudden Type-Safety in XSLT 2.0


I think this discussion misses the point. Changing the version number to
allow/disallow type is at best a kludge. Personally, I think that maybe a
type-safety attribute sitting on the <xsl:stylesheet> node would do the
trick. This would instruct the processor to perform type-safety checking
if
enabled, and would turn that feature off if not. This would mean that
non-type-safe code would be less safe but probably more efficient. As
type-safety is pretty much a concession to Microsoft anyway, it seems to
me
reasonable to make this a flag. Yes, it makes more work for the
implementation coders ... but so what. I've worked with the type-safe mode
now for a couple of weeks, and frankly, its a pain in the butt that lends
very little real benefit for a lot more work.

-- Kurt


----- Original Message -----
From: "Charles White" <chuck(_at_)tumeric(_dot_)net>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, February 25, 2003 1:46 PM
Subject: Re: [xsl] Re: The Perils of Sudden Type-Safety in XSLT 2.0


----- Original Message -----
From: "Gunther Schadow" <gunther(_at_)aurora(_dot_)regenstrief(_dot_)org>

 Certainly there may still be issues with
things like

string-pad(' ', @indent + 2)

because this would @indent + 2 would probably result in an
xs:decimal and not an xs:integer and then there would still be
complaints.

Hi Gunther:

Except I think you're forgetting about the solution of changing the
version
number to 1.0, which, when using XSLT processors that can process 2.0
files,
will give you access to XSLT 2.0 elements and attributes without the
datatyping. That is, if I am correctly interpreting Jeni's response
earlier
in this thread.

That leads to more weirdness, that when you have version="1.0" you are
sometimes working with 2.0 documents.

I actually did my own tests a week or so ago because you took so long to
answer the post you answered previously today. <grin/>

The following won't work in Saxon if the version number is 2.0, but will
if
you change the version number to version="1.0":

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns="http://www.w3.org/1999/xhtml";>

  <xsl:output method="html"/>
    <xsl:variable name="import" select="products" />

  <xsl:template match="/">
    <html>
      <head>
        <title>Links to text documents</title>
      </head>
      <body>
        <p>Click a link to view the files output for this stylesheet</p>
        <ul>
          <xsl:apply-templates select="products/product"/>
        </ul>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="product">
    <xsl:variable name="doclink"
select="normalize-space(concat(local-name(), position(), '.htm'))"/>

    <li>
      <a href="{$doclink}">
        <xsl:value-of select="string-pad($doclink, 1)"/>
      </a>
    </li>

  </xsl:template>

</xsl:stylesheet>

Oh, and this is the source document:

<?xml version="1.0" encoding="UTF-8"?>
<products>
<product >
 <name>Bert&apos;s Coffee</name>
 <quantity>1</quantity>
 <quantity>3</quantity>
 <quantity>3.4</quantity>
 <quantity>8</quantity>
 <selldate>2003-01-21</selldate>
</product>
<product >
 <name>Bert&apos;s Tea</name>
 <quantity>11</quantity>
 <quantity>22</quantity>
 <quantity>11.5</quantity>
 <quantity>8</quantity>
 <selldate>2003-02-21</selldate>
</product>
<product >
 <name>Bert&apos;s Soda</name>
 <quantity>3</quantity>
 <quantity>2</quantity>
 <quantity>5</quantity>
 <quantity>1.5</quantity>
 <selldate>2002-02-15</selldate>
</product>
</products>

The offending statement is this:

 <xsl:variable name="doclink"
select="normalize-space(concat(local-name(),
position(), '.htm'))"/>

I only used the string-pad function to see if I could use XPath 2.0
functions in Saxon while (or, for you English folks out there, whilst)
using
1.0 as the version attribute value, and found that I could.

Of course, you can fix the above statement and make it work with
version="2.0" by doing this:

 <xsl:variable name="doclink"
select="normalize-space(concat(local-name(),
string(position()), '.htm'))"/>

But you don't have to even do that, you can just change the stylesheet's
version attribute value to 1.0.

So, in summary, it seems as though data typing is available if you want
it
to be, and not available if you don't want it to be. If you don't want
it
to
be, you use version="1.0", and you still get to use XSLT/XPath 2.0
syntax,
without type casting. If you do want a stricter type casting model, you
use
version="2.0".

Please, somebody correct me if my interpretation is erroneous!!

I'm not against strict data typing ***IF*** there's a clean way out, and
there seems to be, sort of.

Cheers,


Chuck White
Author, Mastering XSLT, Sybex Books
http://www.javertising.com/webtech
http://www.tumeric.net




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list