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"

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

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

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

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



Oh, and this is the source document:

<?xml version="1.0" encoding="UTF-8"?>
<product >
 <name>Bert&apos;s Coffee</name>
<product >
 <name>Bert&apos;s Tea</name>
<product >
 <name>Bert&apos;s Soda</name>

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

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.


Chuck White
Author, Mastering XSLT, Sybex Books

 XSL-List info and archive:

Current Thread