打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Jan

When last discussing using the XML produced by BIND's statistics server, I showed you how I created a C program to parse the XML, but it didn't occur to me to use XSL and the xsltproc utility to do so.

BIND9 old XML format

A kind reader added a comment to that post a few moments ago, and I took the liberty of streamlining his code a bit to produce this:

<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
  ** XSLT to parse BIND9 XML from the statistics-server (old format)
  ** inspired by a comment by Andrii Shynkarchuk on 
  ** http://jpmens.net/2010/10/21/using-binds-statistics-server-to-list-zones-and-axfr-the-list/
  **
  ** Set the view name you're interested in where it says "_default"
  ** (This could be accessed with an XSLT param or so.)
  -->
<xsl:output method="text" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="isc/bind/statistics">
    <xsl:apply-templates select="views/view">
    </xsl:apply-templates></xsl:template>
      <xsl:template match="views/view">
      <xsl:choose>
    <xsl:when test="name='_default'">
        <xsl:for-each select="zones/zone">
            <xsl:value-of select="serial" />
            <xsl:text> </xsl:text> 
            <!-- zone name only (w/o class/view) -->
            <xsl:value-of select="substring-before(name, '/')" />
            <xsl:text>&#xa;</xsl:text> <!-- newline -->
        </xsl:for-each>

    </xsl:when>
      </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

If I run the result through xsltproc on a 240MB XML file containing 136,000 zones, I get results in 8 seconds on my laptop, which is pretty good.

curl -qs http://172.16.153.101:8053/ |
    xsltproc bconvert.xsl -
2012011108 example.com
0 0.in-addr.arpa
0 1.0.0.127.in-addr.arpa
0 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
2011080707 example.org
97 big.aa
...

BIND9 newstats XML format

And this works for me for the "newstats" format, introduced experimentally in 9.9.3:

<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
  ** XSLT to parse BIND9 (version3) XML from the statistics-server (new format)
  ** inspired by a comment by Andrii Shynkarchuk on 
  ** http://jpmens.net/2010/10/21/using-binds-statistics-server-to-list-zones-and-axfr-the-list/
  **
  ** Set the view name you're interested in where it says "_default"
  ** (This could be accessed with an XSLT param or so.)
  -->
<xsl:output method="text" />
  <xsl:strip-space elements="*"/>

<xsl:template match="statistics"> 
    <xsl:apply-templates select="views/view">
    </xsl:apply-templates></xsl:template>
      <xsl:template match="views/view">
        <xsl:for-each select="zones/zone">
            <xsl:value-of select="serial" />
            <xsl:text> </xsl:text> 
            <xsl:value-of select="@name" />
            <xsl:text>&#xa;</xsl:text> <!-- newline -->
        </xsl:for-each>
</xsl:template> 
</xsl:stylesheet>

Thank you, Andrii. :)

BIND, XML, and XSL :: 01 Mar 2013 :: e-mail

Comments

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
XML认证教程,第 4 部分: XSL样式单
XSLT轻松入门第二章:XSLT的实例
xslt轻松入门(zt)
XSLT语法概要
XPath tutorial
XML卷之实战锦囊(1):动态排序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服