a little nicer wrt pep8
[sfa.git] / sfatables / processors / max_node_kbps.xsl
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3   <!-- Magic sauce copied from a manual. This fragment basically
4     copies everything except for stuff that explicitly matches with
5     the templates defined below. In the case of such a match, the
6     matched node is treated differently.-->
7   <xsl:template match="@* | node()">
8     <xsl:copy>
9       <xsl:apply-templates select="@* | node()"/>
10     </xsl:copy>
11   </xsl:template>
12   <!-- End of magic sauce -->
13
14   <!-- Read in the value of the argument. -->
15   <xsl:variable name="max-node-kbps" select="//RSpec//target-context/argument[name='max-node-kbps']/value"/>
16   <xsl:variable name="blacklist_suffix" select="//RSpec//target-context/argument[name='on-legacy-node']/value"/>
17
18   <!-- Modify NodeSpec for which kbps > max-link-kbps -->
19   <xsl:template match="NodeSpec/max_rate">
20       <xsl:choose>
21           <xsl:when test=". &gt; $max-node-kbps">
22               <max_rate><xsl:value-of select="$max-node-kbps"/></max_rate>
23           </xsl:when>
24           <xsl:otherwise>
25               <xsl:copy-of select="."/>
26           </xsl:otherwise>
27       </xsl:choose>
28   </xsl:template>
29       
30   <!-- Fill in missing kbps values --> 
31   <xsl:template match="NodeSpec[not(max_rate)]">
32       <xsl:choose>
33           <xsl:when test="(not($blacklist_suffix) or not(contains(@name,$blacklist_suffix)))"> 
34               <!-- We're OK on this node, simply copy the nodespec -->
35               <xsl:copy-of select="."/>
36           </xsl:when>
37           <xsl:otherwise>
38               <xsl:choose>
39                   <xsl:when test="not(max_rate)">
40                       <xsl:copy>
41                           <xsl:copy-of select="@*"/>
42                           <max_rate><xsl:value-of select="$max-node-kbps"/></max_rate>
43                       </xsl:copy>
44                   </xsl:when>
45                   <xsl:otherwise>
46                       <xsl:choose>
47                           <xsl:when test=". &gt; $max-node-kbps">
48                               <max_rate><xsl:value-of select="$max-node-kbps"/></max_rate>
49                           </xsl:when>
50                           <xsl:otherwise>
51                               <xsl:copy-of select="."/>
52                           </xsl:otherwise>
53                       </xsl:choose>
54                   </xsl:otherwise>
55               </xsl:choose>
56           </xsl:otherwise>
57       </xsl:choose>
58   </xsl:template>
59   <xsl:template match="sfatables-input"/>
60 </xsl:stylesheet>