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.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u