Stopping DocBook Version Control Churn

I have been getting frustrated with DocBook’s generation of HTML files, because it seems to gratuitously insert random id’s for things in a pattern that doesn’t repeat, so you run xsltproc on the same file twice, and the output changes. subversion, git, etc… pick up on the differences and want to save the new version, which is quite annoying.

I figured out a way to get around this. I have no idea if it’s ugly or not, but it works and that’s enough for me. Comments/ideas/improvements welcome.

<xsl:template name="object.id">
  <xsl:param name="object" select="."/>
  <xsl:choose>
<xsl:when test="$object/@id">
  <xsl:value-of select="$object/@id"/>
</xsl:when>
<xsl:when test="$object/@xml:id">
  <xsl:value-of select="$object/@xml:id"/>
</xsl:when>
<xsl:otherwise>
  id-<xsl:number level="multiple" count="*"/>
</xsl:otherwise>
  </xsl:choose>
</xsl:template>

The key is the line:

  id-<xsl:number level="multiple" count="*"/>

which replaces

  <xsl:value-of select="generate-id($object)"/>

The problem is that generate-id, at least in xsltproc, uses a fairly random bit of data (memory location) to create the id.

My fix uses the location of the element within the document as the id.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s