f09a56fe3c9751e8610f6e1745ac551fd343c18f
[sfa.git] / sfatables / processors / restrict_to_nodes.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 copies everything except for
4     stuff that explicitly matches with the templates defined below. In the case of such a match,
5     the matched node is treated differently.-->
6     <xsl:template match="@* | node()">
7         <xsl:copy>
8             <xsl:apply-templates select="@* | node()"/>
9         </xsl:copy>
10     </xsl:template>
11
12     <xsl:variable name="whitelist_prefix" select="//rspec//sfatables-rule/argument[name='whitelist']/value"/>
13     <xsl:variable name="blacklist_prefix" select="//rspec//sfatables-rule/argument[name='blacklist']/value"/>
14
15     <!-- Drop nodes that are not in the whitelist -->
16     <xsl:template match="node">
17             <xsl:choose>
18                 <xsl:when test="starts-with(@name,$whitelist_prefix) and not($blacklist_prefix and starts-with(@name,$blacklist_prefix))">
19                     <xsl:copy-of select="."/>
20                 </xsl:when>
21                 <xsl:otherwise/>
22             </xsl:choose>
23     </xsl:template>
24
25 </xsl:stylesheet>