_xmlcatalog() {
  xmlcatalog --noout "$@" etc/xml/catalog
}

post_install() {
  [[ -f etc/xml/catalog ]] || _xmlcatalog --create

  local ver x new=${1%-*}

  for ver in $new current; do
    for x in rewriteSystem rewriteURI; do
      _xmlcatalog --add $x http://cdn.docbook.org/release/xsl/$ver \
        /usr/share/xml/docbook/xsl-stylesheets-$new

      _xmlcatalog --add $x http://cdn.docbook.org/release/xsl-nons/$ver \
        /usr/share/xml/docbook/xsl-stylesheets-$new-nons

      _xmlcatalog --add $x http://docbook.sourceforge.net/release/xsl-ns/$ver \
        /usr/share/xml/docbook/xsl-stylesheets-$new

      _xmlcatalog --add $x http://docbook.sourceforge.net/release/xsl/$ver \
        /usr/share/xml/docbook/xsl-stylesheets-$new-nons
    done
  done
}

post_upgrade() {
  post_remove $2
  post_install $1
}

post_remove() {
  local old=${1%-*}
  _xmlcatalog --del /usr/share/xml/docbook/xsl-stylesheets-$old
  if (( $(vercmp $1 1.79.2-5) >= 0 )); then
    _xmlcatalog --del /usr/share/xml/docbook/xsl-stylesheets-$old-nons
  fi
}

# vim:set ft=sh sw=2 et:
