123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed Materials - Property of IBM
- IBM Cognos Products: ps
- (C) Copyright IBM Corp. 2005, 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:cm="http://developer.cognos.com/schemas/xts-cm/1/"
- exclude-result-prefixes="xsl cm">
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
-
- <xsl:key name="env-param" match="/content/env/param" use="@name"/>
- <xsl:key name="nav-param" match="/content/env/param[starts-with(@name,'nav_checkbox')]" use="."/>
- <xsl:key name="list-param" match="/content/env/param[starts-with(@name,'list_checkbox')]" use="."/>
- <xsl:key name="type-entries" match="/content/entry/results/cm:queryResponse/*/*[local-name()='searchPath']" use="."/>
- <xsl:template match="/content" priority="1">
- <content>
- <cm:queryResponse>
- <xsl:copy-of select="cm:queryResponse/cm:queryReply[position()='1' or position()='2']"/>
- </cm:queryResponse>
- </content>
- <xsl:if test="starts-with(/content/action, 'add')">
- <xsl:apply-templates select="." mode="add"/>
- </xsl:if>
- <xsl:if test="starts-with(/content/action, 'remove')">
- <xsl:apply-templates select="." mode="remove"/>
- </xsl:if>
- </xsl:template>
-
- <!-- user hit the remove button -->
- <xsl:template match="*" mode="remove">
- <selectedEntries>
- <xsl:for-each select="/content/*[local-name()='selectedEntries']/*">
- <!-- make the position 0 based since we used preceding-sibling for the
- checkbox value which is 0 based -->
- <xsl:variable name="pos" select="position()-1"/>
-
- <xsl:if test="not(key('list-param',$pos))">
- <xsl:copy-of select="."/>
- </xsl:if>
- </xsl:for-each>
- </selectedEntries>
- </xsl:template>
- <!-- user hit the add button -->
- <xsl:template match="*" mode="add">
-
- <!-- flag duplicate entries if allowDuplicated is set to false -->
- <xsl:choose>
- <xsl:when test="/content/dialog != 'type' and /content/allowDuplicates = 'false' and key('nav-param', /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath'])">
- <duplicateEntry>true</duplicateEntry>
- </xsl:when>
- <xsl:when test="/content/dialog = 'type' and /content/allowDuplicates = 'false' and key('type-entries', /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath'])">
- <duplicateEntry>true</duplicateEntry>
- </xsl:when>
- </xsl:choose>
- <xsl:if test="/content/dialog = 'type'">
- <invalid_typed_entries>
- <xsl:for-each select="/content/entry[not(results/cm:queryResponse/*)]">
- <xsl:value-of select="namespace-name"/>
- <xsl:if test="object-name!=''">
- <xsl:value-of select="concat('/',object-name)"/>
- </xsl:if>
- <xsl:text>; </xsl:text>
- </xsl:for-each>
- </invalid_typed_entries>
- </xsl:if>
- <selectedEntries>
- <!-- copy over the entries that were already added -->
- <xsl:copy-of select="./*[local-name()='selectedEntries']/*"/>
-
- <xsl:choose>
- <!-- adding entries from the type tab -->
- <xsl:when test="/content/dialog = 'type'">
- <xsl:for-each select="/content/entry/results/cm:queryResponse/*/*[local-name()='searchPath']">
- <xsl:variable name="searchPath" select="."/>
- <!-- don't add duplicated if allowDuplicate is false -->
- <xsl:if test="/content/allowDuplicates = 'true' or not(/content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath' and string(.) = $searchPath])">
- <xsl:apply-templates select="/content/entry/results/cm:queryResponse/*[*[local-name()='searchPath' and string(.) = $searchPath]]" mode="addItem"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:for-each select="/content/env/param[@name = 'nav_checkbox']">
- <xsl:variable name="searchPath" select="."/>
- <xsl:choose>
- <!-- don't add duplicate entries if allowDuplicated is set to false -->
- <xsl:when test="/content/allowDuplicates = 'false' and /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath' and string(.) = $searchPath]"/>
- <xsl:when test="/content/cm:queryResponse/cm:queryReply[position() >= number(/content/addedQueryPosition)]/*/*[local-name()='searchPath' and string(.) = $searchPath]">
- <xsl:apply-templates select="/content/cm:queryResponse/cm:queryReply[position() >= number(/content/addedQueryPosition)]/*[*[local-name()='searchPath' and string(.) = $searchPath]]" mode="addItem"/>
- </xsl:when>
- </xsl:choose>
- </xsl:for-each>
- </xsl:otherwise>
- </xsl:choose>
- </selectedEntries>
- </xsl:template>
-
- <xsl:template match="*" mode="addItem">
- <!-- find out if the user hit the add 'To', 'Cc', 'Bcc' or the standard add button -->
- <xsl:variable name="type" select="substring-after(/content/action, 'add_')"/>
-
- <xsl:element name="{local-name()}" namespace="http://developer.cognos.com/schemas/xts-cm/1/">
- <xsl:if test="$type != ''">
- <type><xsl:value-of select="$type"/></type>
- </xsl:if>
- <xsl:apply-templates mode="addProperties"/>
- </xsl:element>
- </xsl:template>
-
- <xsl:template match="*" mode="addProperties">
- <xsl:variable name="propertyName" select="local-name()"/>
- <xsl:if test="$propertyName = 'searchPath' or $propertyName = 'objectClass' or $propertyName = 'defaultName' or $propertyName = 'base' or $propertyName='searchPathForURL' or $propertyName='hidden' or /content/*[local-name()='property' and @name=$propertyName]">
- <xsl:copy-of select="."/>
- </xsl:if>
- <xsl:if test="$propertyName = 'ancestors'">
- <xsl:element name="{local-name()}" namespace="http://developer.cognos.com/schemas/xts-cm/1/">
- <xsl:copy-of select="./*"/>
- </xsl:element>
- </xsl:if>
- </xsl:template>
-
- <xsl:template match="text()" priority="0"/>
- </xsl:stylesheet>
|