MINGW_INSTALL=mingw64
MINGW_XML_CATALOG=${MINGW_INSTALL}/etc/xml

_xmlcatalog() {
  /${MINGW_INSTALL}/bin/xmlcatalog.exe --noout "$@" ${MINGW_XML_CATALOG}/catalog
}

post_install() {
  [[ -f /${MINGW_XML_CATALOG}/catalog ]] || _xmlcatalog --create

  local x
  for x in "delegateSystem" "delegateURI"; do
    _xmlcatalog --add $x \
      "http://docbook.sourceforge.net/release/xsl/" \
      "./docbook-xsl" 

    _xmlcatalog --add $x \
      "http://docbook.sourceforge.net/release/xsl-ns/" \
      "./docbook-xsl" 

    _xmlcatalog --add $x \
      "http://cdn.docbook.org/release/xsl/" \
      "./docbook-xsl" 

    _xmlcatalog --add $x \
      "http://cdn.docbook.org/release/xsl-nons/" \
      "./docbook-xsl" 
  done
}

post_upgrade() {
  post_remove $2
  post_install $1
}

post_remove() {
  local old=${1%-*}
  _xmlcatalog --del ../../share/xml/docbook/xsl-stylesheets-$old
  _xmlcatalog --del "http://docbook.sourceforge.net/release/xsl/"
  _xmlcatalog --del "http://docbook.sourceforge.net/release/xsl-ns/"
  rm -f ${MINGW_XML_CATALOG}/docbook-xsl.xml
  if (( $(vercmp $1 1.79.2-4) >= 0 )); then
    _xmlcatalog --del ../../share/xml/docbook/xsl-stylesheets-$old-nons
  fi
}
