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

Re: getting type information in xslt 2.0

Subject: Re: getting type information in xslt 2.0
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 23 Oct 2006 23:57:33 +0100
xslt fn position
>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

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-2013 All Rights Reserved.