Project

Profile

Help

Bug #2043 ยป Public_Map_error.xsl

David Rudel, 2014-03-27 00:35

 
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
exclude-result-prefixes="xs saxon map">

<xsl:variable name="list.map" as="map(xs:string,xs:string+)">
<xsl:map>
<xsl:map-entry key="'A'" select="('tr','a')"/>
<xsl:map-entry key="'B'" select="('t')"/>
</xsl:map>
</xsl:variable>
<xsl:variable name="sorted.factstamps" as="element()+">
<a factID="184" operationalState="C" date="2013-09-09"/>
<a factID="1" operationalState="B" date="2013-09-12"/>
<a factID="2" operationalState="A" date="2013-09-14"/>
</xsl:variable>

<xsl:variable name="daily.fact.map" as="map(xs:date,map(xs:string,xs:string*))">
<xsl:map>
<xsl:iterate select="$sorted.factstamps">
<xsl:param name="fact.state.map" select="map:new()" as="map(xs:string,xs:string)"/>
<xsl:param name="date" select="$sorted.factstamps[1]/@date" as="xs:string"/>
<xsl:variable name="new.date" select="@date"/>
<xsl:choose>
<xsl:when test="$date = $new.date">
<xsl:next-iteration>
<xsl:with-param name="fact.state.map" select="map:new(($fact.state.map,map{xs:string(@factID) := xs:string(@operationalState)}))"/>
</xsl:next-iteration>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="putative.map" as="map(xs:string,xs:string*)">
<xsl:map>
<xsl:for-each-group select="map:keys($fact.state.map)" group-by="$list.map($fact.state.map(.))">
<xsl:map-entry key="current-grouping-key()" select="current-group()"/>
</xsl:for-each-group>
</xsl:map>
</xsl:variable>
<xsl:map-entry key="xs:date($date)">
<xsl:sequence select="$putative.map"/>
</xsl:map-entry>
<xsl:next-iteration>
<xsl:with-param name="fact.state.map" select="map:new(($fact.state.map,map{xs:string(@factID) := xs:string(@operationalState)}))"/>
<xsl:with-param name="date" select="$new.date"/>
</xsl:next-iteration>
</xsl:otherwise>
</xsl:choose>
</xsl:iterate>
</xsl:map>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="count(map:keys($daily.fact.map))"/>
</xsl:template>

</xsl:stylesheet>
    (1-1/1)