<?xml version="1.0" encoding="utf8"?>
<!--
$Id: warnings.xsl,v 1.1 2005/07/06 08:26:19 jmates Exp $

Checks DocBook files for problems not otherwise warned about.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="articleinfo"/>
  <xsl:template match="section">
<!-- some tools don't error on duplicate IDs (no validity checks?) -->
    <xsl:if test="preceding::section/@id = @id or ancestor::section/@id = @id">
      <xsl:message>
        <xsl:text>error: duplicate id: id=</xsl:text>
        <xsl:value-of select="@id"/>
        <xsl:text>, xpath=/</xsl:text>
        <xsl:for-each select="ancestor::*">
          <xsl:value-of select="name()"/>
<!-- if not id, insert the position number instead? -->
          <xsl:if test="@id">
            <xsl:text>[@id="</xsl:text>
            <xsl:value-of select="@id"/>
            <xsl:text>"]</xsl:text>
          </xsl:if>
          <xsl:text>/</xsl:text>
        </xsl:for-each>
        <xsl:value-of select="name()"/>
        <xsl:text>[position()=</xsl:text>
        <xsl:value-of select="position()"/>
        <xsl:text>]</xsl:text>
      </xsl:message>
    </xsl:if>
<!-- warn about sections without titles -->
    <xsl:if test="string-length(title) = 0">
      <xsl:message>
        <xsl:text>error: section without title: </xsl:text>
        <xsl:text>xpath=/</xsl:text>
        <xsl:for-each select="ancestor::*">
          <xsl:value-of select="name()"/>
<!-- if not id, insert the position number instead? -->
          <xsl:if test="@id">
            <xsl:text>[@id="</xsl:text>
            <xsl:value-of select="@id"/>
            <xsl:text>"]</xsl:text>
          </xsl:if>
          <xsl:text>/</xsl:text>
        </xsl:for-each>
        <xsl:value-of select="name()"/>
        <xsl:text>[position()=</xsl:text>
        <xsl:value-of select="position()"/>
        <xsl:text>]</xsl:text>
      </xsl:message>
    </xsl:if>
    <xsl:apply-templates select="section"/>
  </xsl:template>
</xsl:stylesheet>
