Generate another version of DocBook for your customer

By xngo on June 18, 2019

Sometimes you want to generate a different version of your docbook for your customer. In my case, I was using the common attribute role to mark the content that I don't want the customer to see. Therefore, I set role="NotForClient" on all nodes that I don't want my customer to see. Then, I apply an XSL stylesheet to remove those nodes.

Here is the XSL stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                                    xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <!-- Copy everything -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
 
  <!-- 
  In order to remove all nodes that has the attribute role="NotForClient",
  write a template as below to catch all nodes with @role='NotForClient' and do nothing.
  Therefore, the node is removed.
  -->
  <xsl:template match="*[@role='NotForClient']" />
 
</xsl:stylesheet>

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.