123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed Materials - Property of IBM
- BI and PM: ps
- (C) Copyright IBM Corp. 2010, 2011
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- -->
- <!--
- Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
- Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
- -->
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:out="dummy-uri"
- xmlns:psdp="http://developer.cognos.com/schemas/xts/logicsheet/xslt/propertiesSettings/durationProperty/"
- exclude-result-prefixes="xsl">
-
- <xsl:output method="xml" encoding="UTF-8" indent="no"/>
- <xsl:namespace-alias result-prefix="xsl" stylesheet-prefix="out"/>
-
- <xsl:template match="psdp:durationConvertors">
-
- <!--
- Generates the following formatted string unitNbr:unit from
- the formatted PnYnMnDTnHnMnS; it extracts the most significant value from
- month to second
- Example:
- P1Y23M will generate 23:months
- P34DT12H will generate 34:days
- -->
- <out:template name="parseDurationValue">
- <out:param name="duration"/>
-
- <!-- Extract year, month and days -->
- <out:variable name="yearMonthDay">
- <out:choose>
- <out:when test="contains($duration,'T')">
- <out:value-of select="substring-before($duration,'T')"/>
- </out:when>
- <out:otherwise>
- <out:value-of select="$duration"/>
- </out:otherwise>
- </out:choose>
- </out:variable>
-
- <!-- extract month day -->
- <out:variable name="monthDay">
- <out:choose>
- <out:when test="contains($yearMonthDay,'Y')">
- <out:value-of select="substring-after($yearMonthDay,'Y')"/>
- </out:when>
- <out:otherwise>
- <out:value-of select="substring-after($yearMonthDay,'P')"/>
- </out:otherwise>
- </out:choose>
- </out:variable>
-
- <!-- Extract the hour minute seconds -->
- <out:variable name="hourMinuteSecond">
- <out:choose>
- <out:when test="contains($duration,'T')">
- <out:value-of select="substring-after($duration,'T')"/>
- </out:when>
- <out:otherwise></out:otherwise>
- </out:choose>
- </out:variable>
-
- <out:variable name="parsedDuration">
- <out:choose>
- <out:when test="$monthDay!=''">
- <out:choose>
- <out:when test="contains($monthDay,'M')">
- <out:variable name="months">
- <out:value-of select="substring-before($monthDay,'M')"/>
- </out:variable>
- <out:if test="$months!=''">
- <out:value-of select="concat($months,':months')"/>
- </out:if>
- <out:if test="$months=''">
- <out:value-of select="'0:months'"/>
- </out:if>
- </out:when>
- <out:when test="contains($monthDay,'D')">
- <out:variable name="days">
- <out:value-of select="substring-before($monthDay,'D')"/>
- </out:variable>
- <out:if test="$days!=''">
- <out:value-of select="concat($days,':days')"/>
- </out:if>
- <out:if test="$days=''">
- <out:value-of select="'0:days'"/>
- </out:if>
- </out:when>
- <out:otherwise>0:months</out:otherwise>
- </out:choose>
- </out:when>
- <out:when test="$hourMinuteSecond!=''">
- <out:choose>
- <out:when test="contains($hourMinuteSecond,'H')">
- <out:variable name="hours">
- <out:value-of select="substring-before($hourMinuteSecond,'H')"/>
- </out:variable>
- <out:if test="$hours!=''">
- <out:value-of select="concat($hours,':hours')"/>
- </out:if>
- <out:if test="$hours=''">
- <out:value-of select="'0:hours'"/>
- </out:if>
- </out:when>
- <out:when test="contains($hourMinuteSecond,'M')">
- <out:variable name="minutes">
- <out:value-of select="substring-before($hourMinuteSecond,'M')"/>
- </out:variable>
- <out:if test="$minutes!=''">
- <out:value-of select="concat($minutes,':minutes')"/>
- </out:if>
- <out:if test="$minutes=''">
- <out:value-of select="'0:minutes'"/>
- </out:if>
- </out:when>
- <out:when test="contains($hourMinuteSecond,'S')">
- <out:variable name="seconds">
- <out:value-of select="substring-before($hourMinuteSecond,'S')"/>
- </out:variable>
- <out:if test="$seconds!=''">
- <out:value-of select="concat($seconds,':seconds')"/>
- </out:if>
- <out:if test="$seconds=''">
- <out:value-of select="'0:seconds'"/>
- </out:if>
- </out:when>
- <out:otherwise>0:hours</out:otherwise>
- </out:choose>
- </out:when>
- <out:otherwise>0:months</out:otherwise>
- </out:choose>
- </out:variable>
-
- <out:value-of select="$parsedDuration"/>
- </out:template>
-
- <!--
- Build the duration value for the unit number and unit; this is the opposite of
- parseDurationValue
- xxx:months is converted into PxxxM
- -->
- <out:template name="buildDurationValue">
- <out:param name="durationUnitNbr"/>
- <out:param name="durationUnit"/>
-
- <out:choose>
- <out:when test="$durationUnit='months'">
- <out:value-of select="concat('P',$durationUnitNbr,'M')"/>
- </out:when>
- <out:when test="$durationUnit='days'">
- <out:value-of select="concat('P',$durationUnitNbr,'D')"/>
- </out:when>
- <out:when test="$durationUnit='hours'">
- <out:value-of select="concat('PT',$durationUnitNbr,'H')"/>
- </out:when>
- <out:when test="$durationUnit='minutes'">
- <out:value-of select="concat('PT',$durationUnitNbr,'M')"/>
- </out:when>
- <out:when test="$durationUnit='seconds'">
- <out:value-of select="concat('PT',$durationUnitNbr,'S')"/>
- </out:when>
- <out:otherwise>P0D</out:otherwise>
- </out:choose>
-
- </out:template>
- </xsl:template>
-
- <xsl:template match="*">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
-
-
- </xsl:stylesheet>
|