Fixed the 'restrict to nodes' target.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 9 Sep 2009 20:34:41 +0000 (20:34 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 9 Sep 2009 20:34:41 +0000 (20:34 +0000)
sfatables/commands/Add.py
sfatables/targets/restrict_to_nodes.xsl

index 26ba543..5064ee6 100644 (file)
@@ -39,8 +39,6 @@ class Add(Command):
 
             if (hasattr(match_options,option_name)):
                 context = p.xpathEval("//rule/argument[name='%s']"%option_name)
-                import pdb
-                pdb.set_trace()
                 if (not context):
                     raise Exception('Unknown option %s for match %s'%(option,option['name']))
                 else:
index bf63cbc..2ecba22 100644 (file)
@@ -1,9 +1,26 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0"
-    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-    <xsl:template match="/">
-        <xsl:variable name="whitelist_prefix" select="//rule/argument[name='whitelist']/value"/>
-        <xsl:variable name="nodes_minus_whitelist" select="//request/nodespec/node"/>
-        <xsl:value-of select="$nodes_minus_whitelist"/>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <!-- Magic sauce copied from a manual. This fragment basically copies everything except for
+    stuff that explicitly matches with the templates defined below. In the case of such a match,
+    the matched node is treated differently.-->
+    <xsl:template match="@* | node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@* | node()"/>
+        </xsl:copy>
     </xsl:template>
+
+    <xsl:variable name="whitelist_prefix" select="//rspec//rule/argument[name='whitelist']/value"/>
+    <xsl:variable name="blacklist_prefix" select="//rspec//rule/argument[name='blacklist']/value"/>
+
+    <!-- Drop nodes that are not in the whitelist -->
+    <xsl:template match="node">
+            <xsl:choose>
+                <xsl:when test="starts-with(@name,$whitelist_prefix) and not($blacklist_prefix and starts-with(@name,$blacklist_prefix))">
+                    <xsl:copy-of select="."/>
+                </xsl:when>
+                <xsl:otherwise/>
+            </xsl:choose>
+    </xsl:template>
+
+    <xsl:template match="sfatables-input"/>
 </xsl:stylesheet>