a little nicer wrt pep8
[sfa.git] / sfatables / processors / slice-whitelist.xsl
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!-- This is a good example of an sfatables match. It's function is to verify the slice in context against a whitelist -->
3
4 <!-- The following lines should precede each match/target. -->
5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6     xmlns:exsl="http://exslt.org/common"
7     extension-element-prefixes="exsl"
8     version="1.0">
9
10     <!-- Enter your whitelist prefixes here. Since XSLT cannot read from/write to an external archive, we need to embed the whitelist in here -->
11
12     <xsl:variable name="whitelist_data">
13         <hrn>plc.princeton.acb</hrn>
14         <hrn>plc.princeton.sapanb</hrn>
15         <hrn>plc.princeton.codeen</hrn>
16     </xsl:variable>
17
18     <!-- Read the whitelist into a variable. Normally, one should be able to refer to $whitelist_data directly, but apparently this is something you need to do because libxml2 does not support xslt 2.0 -->
19
20     <xsl:variable name="whitelist" select="exsl:node-set($whitelist_data)/hrn"/>
21
22     <!-- Read the value of the current slice's hrn -->
23     <xsl:variable name="current_slice_hrn" select="//request-context/sfa/slice/hrn"/>
24
25     <!-- Define a function that checks if one of a list of prefixes (lst) matches $current_slice_hrn". It's a stupid idea to call a function a 'template' but whatever...  -->
26     <xsl:template name="recurse_list">
27         <xsl:param name="lst"/>
28         <xsl:choose>
29             <xsl:when test="count($lst)!=0">
30                 <!-- Indexing in xpath has a base=1 -->
31                 <xsl:variable name="head" select="$lst[1]"/>
32                 <xsl:choose>
33                     <xsl:when test="starts-with($current_slice_hrn,$head)">
34                         <result verdict="True"/>
35                     </xsl:when>
36                     <xsl:otherwise>
37                         <xsl:call-template name="recurse_list">
38                             <xsl:with-param name="lst" select="$lst/following-sibling::*"/>
39                         </xsl:call-template>
40                     </xsl:otherwise>
41                 </xsl:choose>
42             </xsl:when>
43             <xsl:otherwise>
44                 <result verdict="False"/>
45             </xsl:otherwise>
46         </xsl:choose>
47     </xsl:template>
48
49     <xsl:template match="/">
50         <xsl:call-template name="recurse_list">
51             <xsl:with-param name="lst" select="$whitelist"/>
52         </xsl:call-template>
53     </xsl:template>
54 </xsl:stylesheet>