Skip to content

Instantly share code, notes, and snippets.

@putnamhill
Last active February 3, 2023 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save putnamhill/9bf35720bec0bc60a6e4a79d310e058e to your computer and use it in GitHub Desktop.
Save putnamhill/9bf35720bec0bc60a6e4a79d310e058e to your computer and use it in GitHub Desktop.
parse firewall rules with xslt

parse firewall rules with xslt

to run

xsltproc firewall.xsl source.xml

to test with bash

diff --report-identical-files <(xsltproc firewall.xsl source.xml) expect

If the results of the process substitution are the same as the file expect, then the test has passed.

169.25
169.25
169.25
169.25
224.81
158.87
149.131
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="*" />
<xsl:template match="//firewallRule[action/text() = 'accept']">
<xsl:apply-templates select="source|destination"/>
</xsl:template>
<xsl:template match="source|destination">
<xsl:apply-templates select="ipAddress"/>
</xsl:template>
<xsl:template match="ipAddress">
<xsl:value-of select="." />
<xsl:text>&#x0a;</xsl:text>
</xsl:template>
<!-- override default built-in text() template -->
<xsl:template match="text()" />
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment