Re: [xsl] getting type information in xslt 2.0

Subject: Re: [xsl] getting type information in xslt 2.0
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 23 Oct 2006 16:47:47 -0700
Very briefly, all the functions in your example are typeless.

If we had to use typeless functions in FXSL, we'd not need type information.




-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play

On 10/23/06, David Carlisle <davidc@xxxxxxxxx> wrote:

>How ???


Hmm perhaps something like this. I suspect that it needs restructuring
to deal with lists-of-lists I thought I'd need that even for the first
examples but I seem to have got away with it so far.

saxon8 -it main curry.xsl
<?xml version="1.0" encoding="UTF-8"?>
  sq    1 4 9 16 25 36
  p1    <f:plus xmlns:f="data:,f"/>1
  p1p3  4
  mapp1int 2 3 4 5 6 7
  mapp1double 2.1 3.1 4.1 5.1 6.1 7.1
  mapp1date 1999-02-01 1999-02-02 1999-02-03 1999-02-04 1999-02-05 1999-02-06


which I claim shows the partial application of + to 1 being used as an "increment by 1" function and mapped over the sequence 1 to 6 as integer double or dates of some sort with types being kept intact.

Code not tested at all apart from this one example:-)

David


<xsl:stylesheet version="2.0"


                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                               xmlns:xs="http://www.w3.org/2001/XMLSchema";
                                       xmlns:f="data:,f"
                                               exclude-result-prefixes="xs f">


<xsl:variable name="arg" as="element()"> <f:arg/> </xsl:variable> <xsl:variable name="plus" as="element()"> <f:plus/> </xsl:variable> <xsl:variable name="times" as="element()"> <f:times/> </xsl:variable> <xsl:variable name="square" as="element()"> <f:square/> </xsl:variable> <xsl:variable name="map" as="element()"> <f:map/> </xsl:variable>

<xsl:function name="f:apply"  as="item()*">
   <xsl:param name="fn" as="item()+"/>
   <xsl:param name="args" as="item()*"/>
   <xsl:choose>
     <xsl:when test="count($fn)=1">
     <xsl:apply-templates select="$fn">
       <xsl:with-param name="args" select="$args"/>
       </xsl:apply-templates>
     </xsl:when>
     <xsl:otherwise>
     <xsl:apply-templates select="$fn[1]">
       <xsl:with-param name="args" select="$fn[position()!=1],$args"/>
       </xsl:apply-templates>
     </xsl:otherwise>
   </xsl:choose>
</xsl:function>

<xsl:function name="f:map" as="item()*">
   <xsl:param name="fn" as="item()+"/>
   <xsl:param name="args" as="item()*"/>
   <xsl:sequence select="for $i in $args return f:apply($fn,$i)"/>
</xsl:function>

<xsl:template match="f:plus">
   <xsl:param name="args" as="item()*"/>
   <xsl:choose>
     <xsl:when test="count($args)=2">
     <xsl:sequence select="$args[1]+$args[2]"/>
     </xsl:when>
     <xsl:otherwise>
     <xsl:variable name="q" as="element()"><f:q/></xsl:variable>
     <xsl:sequence select="$plus,$args"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template match="f:square">
   <xsl:param name="args" as="item()*"/>
   <xsl:choose>
     <xsl:when test="count($args)=1">
     <xsl:sequence select="$args[1]*$args[1]"/>
     </xsl:when>
     <xsl:otherwise>
     <xsl:sequence select="$square,$args"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:variable name="intlist" as="xs:integer+" select="(1,2,3,4,5,6)"/>
<xsl:variable name="doublelist" as="xs:double+"
select="(1,2,3,4,5,6)"/>
<xsl:variable name="datelist" as="xs:date+" select="for $d in
(1,2,3,4,5,6) return xs:date(concat('1999-01-0',$d))"/>

<xsl:template name="main">
   sq    <xsl:sequence select="f:map($square,$intlist)"/>
   p1    <xsl:sequence select="f:apply($plus,1)"/>
   p1p3  <xsl:sequence select="f:apply(f:apply($plus,1),3)"/>
   mapp1int <xsl:sequence select="f:map(f:apply($plus,1),$intlist)"/>
   mapp1double <xsl:sequence
   select="f:map(f:apply($plus,1.1),$doublelist)"/>
   mapp1date <xsl:sequence
   select="f:map(f:apply($plus,xs:yearMonthDuration('P1M')),$datelist)"/>

</xsl:template>


</xsl:stylesheet>

Current Thread