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="">
  <xsl:param name="object" select="."/>
<xsl:when test="$object/@id">
  <xsl:value-of select="$object/@id"/>
<xsl:when test="$object/@xml:id">
  <xsl:value-of select="$object/@xml:id"/>
  id-<xsl:number level="multiple" count="*"/>

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: Logo

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

Facebook photo

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

Connecting to %s