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

Subject: Re: [xsl] Re: The Perils of Sudden Type-Safety in XSLT 2.0
From: "Charles White" <chuck@xxxxxxxxxxx>
Date: Tue, 25 Feb 2003 13:46:24 -0800
----- Original Message -----
From: "Gunther Schadow" <gunther@xxxxxxxxxxxxxxxxxxxxxx>

>  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


Current Thread