RSS 2.0
Sign In
# Sunday, 18 May 2008

Recently I've proposed to add two new atomic types tuple and map to the xpath/xslt/xquery type system (see "Tuples an maps"). Later I've implemented tuple and map pure xslt approximation. Now I want to present java implementation for Saxon.

I've created TupleValue and MapValue atomic types, and Collections class exposing extension functions api. It's easy to use this api. I'll repeat an example that I was showing earlier:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:f="http://www.nesterovsky-bros.com/xslt/functions/public"
  xmlns:p="http://www.nesterovsky-bros.com/xslt/functions/private"
  xmlns:c="java:com.nesterovskyBros.saxon.Functions"
  exclude-result-prefixes="xs f p c">

<xsl:template match="/">
   <root>
     <xsl:variable name="tuples" as="item()*" select="
       for $i in 1 to 20
         return c:tuple(1 to $i)"/>

    <total-items>
      <xsl:sequence select="
        sum
        (
          for $tuple in $tuples return
            count(c:tuple-items($tuple))
        )"/>
    </total-items>
    <tuples-size>
      <xsl:sequence select="count($tuples)"/>
    </tuples-size>
    <sums-per-tuples>
      <xsl:for-each select="$tuples">
        <xsl:variable name="index" as="xs:integer" select="position()"/>

        <sum index="{$index}" value="{sum(c:tuple-items(.))}"/>
      </xsl:for-each>
    </sums-per-tuples>

    <xsl:variable name="cities" as="element()*">
      <city name="Jerusalem" country="Israel"/>
      <city name="London" country="Great Britain"/>
      <city name="Paris" country="France"/>
      <city name="New York" country="USA"/>
      <city name="Moscow" country="Russia"/>
      <city name="Tel Aviv" country="Israel"/>
      <city name="St. Petersburg" country="Russia"/>
     </xsl:variable>

    <xsl:variable name="map" as="item()" select="
      c:map
      (
        for $city in $cities return
        (
          $city/string(@country),
          $city
        )
      )"/>

    <xsl:for-each select="c:map-keys($map)">
      <xsl:variable name="key" as="xs:string" select="."/>

      <country name="{$key}">
        <xsl:sequence select="c:map-value($map, $key)"/>
     </country>
    </xsl:for-each>
  </root>
</xsl:template>

</xsl:stylesheet>

Download java source.

P.S. I would wish this api be integrated into Saxon, as at present java extension functions are called through reflection.

Sunday, 18 May 2008 08:44:09 UTC  #    Comments [2] -
Announce | xslt
Monday, 08 December 2008 14:00:20 UTC
Running Saxon-B 9.1.0.2 on this as follows, I get a StackOverflowError. Probably some user error, I guess.

java -cp saxon9.jar;saxon.extensions.jar net.sf.saxon.Transform tuple-test-2.xsl tuple-test-2.xsl

Exception in thread "main" java.lang.StackOverflowError
at net.sf.saxon.type.TypeHierarchy$ItemTypePair.equals(TypeHierarchy.java:425)
at java.util.concurrent.ConcurrentHashMap$Segment.get(Unknown Source)
at java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
at net.sf.saxon.type.TypeHierarchy.relationship(TypeHierarchy.java:110)
at net.sf.saxon.type.TypeHierarchy.isSubType(TypeHierarchy.java:87)
at net.sf.saxon.expr.PJConverter.allocate(PJConverter.java:148)
at net.sf.saxon.expr.PJConverter$Atomic.convert(PJConverter.java:819)
at net.sf.saxon.expr.PJConverter$Atomic.convert(PJConverter.java:821)
at net.sf.saxon.expr.PJConverter$Atomic.convert(PJConverter.java:821)
at net.sf.saxon.expr.PJConverter$Atomic.convert(PJConverter.java:821)
[1014 more of these snipped]
Michael Ludwig
Monday, 08 December 2008 15:12:59 UTC
Michael,

Thank you for pointing to the problem.
Exception occured due to changes in Saxon 9.1.0.2 (compared with 9.1.0.1)
Code is fixed. You can try again.

Thanks.
Vladimir Nesterovsky
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview
Archive
<2008 May>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Statistics
Total Posts: 387
This Year: 3
This Month: 0
This Week: 0
Comments: 1859
Locations of visitors to this page
Disclaimer
The opinions expressed herein are our own personal opinions and do not represent our employer's view in anyway.

© 2024, Nesterovsky bros
All Content © 2024, Nesterovsky bros
DasBlog theme 'Business' created by Christoph De Baene (delarou)