common/sysdefdowngrade/filter-module.xsl
changeset 852 41f42b520ea7
equal deleted inserted replaced
851:82a4f1e453fb 852:41f42b520ea7
       
     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 	<xsl:output method="xml" indent="yes"/>
       
     4 
       
     5 
       
     6 <!-- filters can only return hide or show -->
       
     7 
       
     8 <!-- filter-only =  item's @filter can only have items from the list
       
     9 	anything with no filters passes
       
    10 -->
       
    11 <xsl:template match="filter-only" mode="filter"><xsl:param name="item"/>
       
    12 	<xsl:if test="$item[@filter]">
       
    13 		<xsl:variable name="this" select="."/>
       
    14 		<xsl:variable name="my-filters">
       
    15 			<xsl:call-template name="filter-list">
       
    16 				<xsl:with-param name="f" select="$item/parent::component/@filter"/>
       
    17 			</xsl:call-template>
       
    18 			<xsl:call-template name="filter-list">
       
    19 				<xsl:with-param name="f" select="$item/@filter"/>
       
    20 			</xsl:call-template>
       
    21 		</xsl:variable>
       
    22 		<xsl:variable name="match">
       
    23 			<xsl:for-each select="exslt:node-set($my-filters)/*">
       
    24 				<xsl:if test="not($this/*[name()=name(current())  and @v=current()/@v])">x</xsl:if>
       
    25 			</xsl:for-each>
       
    26 		</xsl:variable>
       
    27 		<xsl:if test="$match!=''">hide</xsl:if>
       
    28 	</xsl:if>
       
    29 </xsl:template>
       
    30 
       
    31 
       
    32 
       
    33 <!-- 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	
       
    34 -->
       
    35 <xsl:template match="filter-has" mode="filter"><xsl:param name="item"/>
       
    36 	<xsl:if test="$item[(self::component or self::unit)  and not(unit/@filter or self::unit[not(../unit[@filter])])]">
       
    37 		<xsl:variable name="my-filters">
       
    38 			<xsl:call-template name="filter-list">
       
    39 				<xsl:with-param name="f" select="$item/parent::component/@filter"/>
       
    40 			</xsl:call-template>
       
    41 			<xsl:call-template name="filter-list">
       
    42 				<xsl:with-param name="f" select="$item/@filter"/>
       
    43 			</xsl:call-template>
       
    44 		</xsl:variable>
       
    45 		<xsl:variable name="match">
       
    46 			<xsl:for-each select="*">
       
    47 				<!-- 	if(f in this) {return true}  else if(!f in this) {return false} else {return !(f is positive)} -->
       
    48 				<xsl:choose>
       
    49 					<xsl:when test="exslt:node-set($my-filters)/*[name()=name(current()) and @v=current()/@v]"/> <!-- filter in item -->
       
    50 					<xsl:when test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:when> <!-- !filter in item -->
       
    51 					<xsl:when test="self::filter">x</xsl:when> <!-- !(filter is positive) -->
       
    52 				</xsl:choose>
       
    53 			</xsl:for-each>
       
    54 		</xsl:variable>
       
    55 		<xsl:if test="$match!=''">hide</xsl:if>
       
    56 	</xsl:if>
       
    57 </xsl:template>
       
    58 
       
    59 <xsl:template match="filter-with" mode="filter"><xsl:param name="item"/>
       
    60 	<xsl:if test="$item[(self::component or self::unit)  and not(unit/@filter or self::unit[not(../unit[@filter])])]">
       
    61 		<xsl:variable name="my-filters">
       
    62 			<xsl:call-template name="filter-list">
       
    63 				<xsl:with-param name="f" select="$item/parent::component/@filter"/>
       
    64 			</xsl:call-template>
       
    65 			<xsl:call-template name="filter-list">
       
    66 				<xsl:with-param name="f" select="$item/@filter"/>
       
    67 			</xsl:call-template>
       
    68 		</xsl:variable>
       
    69 		<xsl:variable name="match">
       
    70 			<xsl:for-each select="*">
       
    71 				<xsl:if test="exslt:node-set($my-filters)/*[name()!=name(current()) and @v=current()/@v]">x</xsl:if> <!-- !filter in item -->
       
    72 			</xsl:for-each>
       
    73 		</xsl:variable>
       
    74 		<xsl:if test="$match!=''">hide</xsl:if>
       
    75 	</xsl:if>
       
    76 </xsl:template>
       
    77 
       
    78 
       
    79 
       
    80 <xsl:template name="filter-item"> <xsl:param name="f"/>
       
    81 	<!-- create an element for a given filter. If the filter's empty make nothing -->
       
    82 	<xsl:choose>
       
    83 		<xsl:when test="$f=''"/>
       
    84 		<xsl:when test="starts-with($f,'!')">
       
    85 				<not v="{substring($f,2)}"/>
       
    86 		</xsl:when>
       
    87 		<xsl:otherwise>
       
    88 				<filter v="{$f}"/>
       
    89 		</xsl:otherwise>
       
    90 	</xsl:choose>
       
    91 </xsl:template>
       
    92 
       
    93 <xsl:template name="filter-list"><xsl:param name="f"/>
       
    94 	<!-- turn a filter list into a set of elements (<filter> or <not>) with the attribute "v" containing the "absolute value" of the filter
       
    95 		filter="A,B,!C" becomes  <filter v="A"/><filter v="B"/><not v="C"/> 
       
    96 	  -->
       
    97 	<xsl:choose>
       
    98 		<xsl:when test="contains($f,',')">
       
    99 			<xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space(substring-before($f,','))"/></xsl:call-template>
       
   100 			<xsl:call-template name="filter-list">
       
   101 				<xsl:with-param name="f" select="substring-after($f,',')"/>
       
   102 			</xsl:call-template>
       
   103 		</xsl:when>
       
   104 		<xsl:otherwise>
       
   105 			<xsl:call-template name="filter-item"><xsl:with-param name="f" select="normalize-space($f)"/></xsl:call-template>
       
   106 		</xsl:otherwise>
       
   107 	</xsl:choose>
       
   108 </xsl:template>
       
   109 
       
   110 </xsl:stylesheet>