|
1 <?xml version="1.0"?> |
|
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt"> |
|
3 <!--Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 All rights reserved. |
|
5 This component and the accompanying materials are made available |
|
6 under the terms of the License "Eclipse Public License v1.0" |
|
7 which accompanies this distribution, and is available |
|
8 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
|
10 Initial Contributors: |
|
11 Nokia Corporation - initial contribution. |
|
12 Contributors: |
|
13 Description: |
|
14 XSLT module which contains the logic to process the filter attribute in the system definition |
|
15 --> |
|
16 <xsl:output method="xml" indent="yes"/> |
|
17 |
|
18 |
|
19 <!-- filters can only return hide or show --> |
|
20 |
|
21 <!-- filter-only = item's @filter can only have items from the list |
|
22 anything with no filters passes |
|
23 --> |
|
24 <xsl:template match="filter-only" mode="filter"><xsl:param name="item"/> |
|
25 <xsl:if test="$item[@filter]"> |
|
26 <xsl:variable name="this" select="."/> |
|
27 <xsl:variable name="my-filters"> |
|
28 <xsl:call-template name="filter-list"> |
|
29 <xsl:with-param name="f" select="$item/parent::component/@filter"/> |
|
30 </xsl:call-template> |
|
31 <xsl:call-template name="filter-list"> |
|
32 <xsl:with-param name="f" select="$item/@filter"/> |
|
33 </xsl:call-template> |
|
34 </xsl:variable> |
|
35 <xsl:variable name="match"> |
|
36 <xsl:for-each select="exslt:node-set($my-filters)/*"> |
|
37 <xsl:if test="not($this/*[name()=name(current()) and @v=current()/@v])">x</xsl:if> |
|
38 </xsl:for-each> |
|
39 </xsl:variable> |
|
40 <xsl:if test="$match!=''">hide</xsl:if> |
|
41 </xsl:if> |
|
42 </xsl:template> |
|
43 |
|
44 |
|
45 |
|
46 <!-- filter-has = item's @filter must have all filters in the list. ie it can have any other filters, but these must all be present |
|
47 --> |
|
48 <xsl:template match="filter-has" mode="filter"><xsl:param name="item"/> |
|
49 <xsl:if test="$item[(self::component or self::unit) and not(unit/@filter or self::unit[not(../unit[@filter])])]"> |
|
50 <xsl:variable name="my-filters"> |
|
51 <xsl:call-template name="filter-list"> |
|
52 <xsl:with-param name="f" select="$item/parent::component/@filter"/> |
|
53 </xsl:call-template> |
|
54 <xsl:call-template name="filter-list"> |
|
55 <xsl:with-param name="f" select="$item/@filter"/> |
|
56 </xsl:call-template> |
|
57 </xsl:variable> |
|
58 <xsl:variable name="match"> |
|
59 <xsl:for-each select="*"> |
|
60 <!-- if(f in this) {return true} else if(!f in this) {return false} else {return !(f is positive)} --> |
|
61 <xsl:choose> |
|
62 <xsl:when test="exslt:node-set($my-filters)/*[name()=name(current()) and @v=current()/@v]"/> <!-- filter in item --> |
|
63 <xsl:when test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:when> <!-- !filter in item --> |
|
64 <xsl:when test="self::filter">x</xsl:when> <!-- !(filter is positive) --> |
|
65 </xsl:choose> |
|
66 </xsl:for-each> |
|
67 </xsl:variable> |
|
68 <xsl:if test="$match!=''">hide</xsl:if> |
|
69 </xsl:if> |
|
70 </xsl:template> |
|
71 |
|
72 <xsl:template match="filter-with" mode="filter"><xsl:param name="item"/> |
|
73 <xsl:if test="$item[(self::component or self::unit) and not(unit/@filter or self::unit[not(../unit[@filter])])]"> |
|
74 <xsl:variable name="my-filters"> |
|
75 <xsl:call-template name="filter-list"> |
|
76 <xsl:with-param name="f" select="$item/parent::component/@filter"/> |
|
77 </xsl:call-template> |
|
78 <xsl:call-template name="filter-list"> |
|
79 <xsl:with-param name="f" select="$item/@filter"/> |
|
80 </xsl:call-template> |
|
81 </xsl:variable> |
|
82 <xsl:variable name="match"> |
|
83 <xsl:for-each select="*"> |
|
84 <xsl:if test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:if> <!-- !filter in item --> |
|
85 </xsl:for-each> |
|
86 </xsl:variable> |
|
87 <xsl:if test="$match!=''">hide</xsl:if> |
|
88 </xsl:if> |
|
89 </xsl:template> |
|
90 |
|
91 |
|
92 |
|
93 <xsl:template name="filter-item"> <xsl:param name="f"/> |
|
94 <!-- create an element for a given filter. If the filter's empty make nothing --> |
|
95 <xsl:choose> |
|
96 <xsl:when test="$f=''"/> |
|
97 <xsl:when test="starts-with($f,'!')"> |
|
98 <not v="{substring($f,2)}"/> |
|
99 </xsl:when> |
|
100 <xsl:otherwise> |
|
101 <filter v="{$f}"/> |
|
102 </xsl:otherwise> |
|
103 </xsl:choose> |
|
104 </xsl:template> |
|
105 |
|
106 <xsl:template name="filter-list"><xsl:param name="f"/> |
|
107 <!-- turn a filter list into a set of elements (<filter> or <not>) with the attribute "v" containing the "absolute value" of the filter |
|
108 filter="A,B,!C" becomes <filter v="A"/><filter v="B"/><not v="C"/> |
|
109 --> |
|
110 <xsl:choose> |
|
111 <xsl:when test="contains($f,',')"> |
|
112 <xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space(substring-before($f,','))"/></xsl:call-template> |
|
113 <xsl:call-template name="filter-list"> |
|
114 <xsl:with-param name="f" select="substring-after($f,',')"/> |
|
115 </xsl:call-template> |
|
116 </xsl:when> |
|
117 <xsl:otherwise> |
|
118 <xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space($f)"/></xsl:call-template> |
|
119 </xsl:otherwise> |
|
120 </xsl:choose> |
|
121 </xsl:template> |
|
122 |
|
123 </xsl:stylesheet> |