123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?xml version="1.0" encoding="UTF-8"?>
- <?xml-stylesheet type="text/xsl" ?>
- <!--
- /*****************************************************************************
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: migv4
- *
- * (C) Copyright IBM Corp. 2003, 2011.
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- ****************************************************************************/
- -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"
- xmlns="http://developer.cognos.com/schemas/report/1/"
- xmlns:x="http://developer.cognos.com/schemas/report/1/"
- xmlns:str="http://www.ora.com/XSLTCookbook/namespaces/strings"
- extension-element-prefixes="str"
- exclude-result-prefixes="x str"
- >
- <xsl:import href="copy.xslt"/>
-
- <xsl:import href="str.find-last.xslt" xmlns:str="http://www.ora.com/XSLTCookbook/namespaces/strings" />
-
- <xsl:output method="xml" />
-
- <xsl:strip-space elements="*"/>
- <xsl:preserve-space elements="x:defaultSelection x:text"/>
-
- <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
- <xsl:template name="merge-conditional-style-variable-expressions">
- <xsl:param name="nodes"/>
- <xsl:param name="pos"/>
- <xsl:variable name="current-variable" select="$nodes[$pos]"/>
- <xsl:choose>
- <xsl:when test="$current-variable">
- <xsl:variable name="expr-text" select="$current-variable/x:expression"/>
- <xsl:variable name="tail" select="' then ( 1 ) else ( 0 )'"/>
- <xsl:variable name="head">
- <xsl:call-template name="str:substring-before-last">
- <xsl:with-param name="input" select="$expr-text"/>
- <xsl:with-param name="substr" select="$tail"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="new-expr-text">
- <xsl:value-of select="$head"/>
- <xsl:text> then (</xsl:text>
- <xsl:text> </xsl:text>
- <xsl:text>'</xsl:text>
- <xsl:value-of select="$pos"/>
- <xsl:text>'</xsl:text>
- <xsl:text> )</xsl:text>
- <xsl:text> else (</xsl:text>
- <xsl:call-template name="merge-conditional-style-variable-expressions">
- <xsl:with-param name="nodes" select="$nodes"/>
- <xsl:with-param name="pos" select="$pos+1"/>
- </xsl:call-template>
- <xsl:text> )</xsl:text>
- </xsl:variable>
- <xsl:value-of select="$new-expr-text"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text> </xsl:text>
- <xsl:text>'</xsl:text>
- <xsl:text>0</xsl:text>
- <xsl:text>'</xsl:text>
- <!-- and quit (stop recursion) -->
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
- <xsl:template match="x:variableList">
- <xsl:variable name="variable-list" select="."/>
- <xsl:variable name="conditional-style-parents" select="//*[ x:conditionalStyle ]"/>
- <variableList>
- <xsl:for-each select="$conditional-style-parents">
- <xsl:if test="count( x:conditionalStyle ) > 1">
- <!-- Build the new single combined selector variable for each set of sibling conditionalStyle-s: -->
- <xsl:variable name="conditional-styles" select="x:conditionalStyle"/>
- <xsl:variable name="referenced-variables" select="$variable-list/x:variable[ @name = $conditional-styles/@refVariable ]"/>
- <variable>
- <xsl:attribute name="name">
- <xsl:call-template name="make-selector-name">
- <xsl:with-param name="parent-node-of-conditional-styles" select="."/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="type">
- <xsl:text>string</xsl:text>
- </xsl:attribute>
- <expression>
- <xsl:call-template name="merge-conditional-style-variable-expressions">
- <xsl:with-param name="nodes" select="$referenced-variables"/>
- <xsl:with-param name="pos" select="1"/>
- </xsl:call-template>
- </expression>
- <variableValueList>
- <!-- Add conditional values: -->
- <xsl:for-each select="$referenced-variables">
- <variableValue >
- <xsl:attribute name="value">
- <xsl:value-of select="position()"/>
- </xsl:attribute>
- </variableValue>
- </xsl:for-each>
- <!-- Add the default value: -->
- <variableValue >
- <xsl:attribute name="value">
- <xsl:value-of select="0"/>
- </xsl:attribute>
- </variableValue>
- </variableValueList>
- </variable>
- </xsl:if>
- </xsl:for-each>
- <!-- Copy all pre-existing report variables: -->
- <!-- !! ToDo: The variable-s that are referred to *only* from conditionalStyle-s can be deleted from this variableList here.
- That is: we may want not to copy any node that is *only* in this node set:
- <xsl:variable name="report-variables-for-conditional-style" select="x:variable[ @name = //x:conditionalStyle/@refVariable ]"/>
- -->
- <xsl:copy-of select="x:variable"/>
- </variableList>
- </xsl:template>
- <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
- <xsl:template name="make-selector-name">
- <xsl:param name="parent-node-of-conditional-styles"/>
- <xsl:text>ConditionalStyleSelector</xsl:text>
- <!-- Make sure this name is unique among report variable-s in the variableList. -->
- <xsl:text>_</xsl:text>
- <xsl:value-of select="generate-id( $parent-node-of-conditional-styles )"/>
- </xsl:template>
- <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
- <xsl:template match="x:conditionalStyle">
- <!-- Delete.
- All sibling conditionalStyle elements will be merged and "single child" conditionalStyle elements will be copied
- by other template in this stylesheet. -->
- </xsl:template>
-
- <xsl:template match="*[ x:conditionalStyle ]">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:variable name="conditional-styles" select="x:conditionalStyle"/>
- <xsl:choose>
- <xsl:when test="count( $conditional-styles) > 1">
- <!-- Copy all contents except sibling conditionalStyle-s (they are removed by other template in this stylesheet) -->
- <xsl:apply-templates/>
- <!-- Merge sibling conditionalStyle-s: -->
- <conditionalStyle>
- <xsl:attribute name="refVariable">
- <xsl:call-template name="make-selector-name">
- <xsl:with-param name="parent-node-of-conditional-styles" select="."/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:for-each select="$conditional-styles">
- <style>
- <xsl:attribute name="refVariableValue">
- <xsl:value-of select="position()"/>
- </xsl:attribute>
- <xsl:copy-of select=".//x:CSS"/>
- </style>
- </xsl:for-each>
- </conditionalStyle>
- </xsl:when>
- <xsl:otherwise>
- <!-- Copy all contents except "single child" conditionalStyle (it is removed by other template in tis stylesheet) -->
- <xsl:apply-templates/>
- <!-- Copy "single child" conditionalStyle: -->
- <xsl:copy-of select="$conditional-styles"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>
|