[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem with iterating through a sequence of integ

Subject: RE: Problem with iterating through a sequence of integers
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 29 Apr 2008 01:50:53 +0100
RE:  Problem with iterating through a sequence of integ
It's the same as doing

<xsl:if test="false()">
  <xsl:value-of select="2 + 'London'"/>
</xsl:if>

Specifically: if there's a type error in an expression that would cause it
inevitably to fail if executed, then a static error can be reported
regardless of the fact that the expression will in fact not be executed.
Without this rule, you would get far fewer compile-time errors, which would
not be a good thing.

I presume this is actually generated code, since I can't imagine any
intelligent human writing it (unless perhaps to test the behaviour of the
processor). It's certainly true that type-checking rules make it harder to
generate code that will get through the compiler, but I think that's a price
worth paying.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Costello, Roger L. [mailto:costello@xxxxxxxxx] 
> Sent: 28 April 2008 21:21
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Problem with iterating through a sequence of integers
> 
> Hi Folks,
> 
> Consider this for-loop which iterates through a sequence.  If 
> the sequence value is a node then apply-templates is called.  
> Otherwise, the value is output:
> 
>     <xsl:for-each select="(1, 2, 3)">
>         <xsl:choose>
>             <xsl:when test=". instance of node()">
>                 <xsl:apply-templates select="." />
>             </xsl:when>
>             <xsl:otherwise>
>                 <xsl:value-of select="."/>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:for-each>
> 
> When I run Saxon, I get this error message:
> 
> 
> Error: Required item type of @select attribute of 
> xsl:apply-templates is node(); supplied value has item type 
> xs:integer Failed to compile stylesheet. 1 error detected.
> 
> 
> If I comment out the apply-templates statement, the for-loop works
> fine.
> 
> It also works fine if I add a node to the for-loop's XPath expression,
> e.g.
> 
>     <xsl:for-each select="(//Book/Author, 1, 2, 3)">
> 
> I'm baffled.  Any ideas?
> 
> /Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.