This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[docbook-apps] Template to convert external cross-references from <xref> to <olink>


I am posting this to share a small piece of template I wrote to convert 
<xref> elements to <olink> where the references are to external documents.

I did this to build a PDF file for each book in a set, where I had
previously been compiling the set into a single HTML Help target or a 
website.
The cross-references between books became external cross-references, 
and I needed to convert those to <olink>s.

This template reuses the target database document used to resolve <olink>
elements (described in Bob Stayton's website at 
http://www.sagehill.net/docbookxsl/Olinking.html)

Here is the tempalte:

  <xsl:template match="xref">
    <xsl:variable name="target" select="@linkend"/>
    <xsl:variable name="role" select="@role"/>
    <xsl:for-each select="document('../olinkdb.xml')"><!-- use for-each to 
change current node (context) to target database document -->
      <xsl:variable name="match" 
select="descendant::div[@targetptr=$target]"/>
      <xsl:variable name="module" 
select="descendant::div[@targetptr=$target]/ancestor::document/@targetdoc"/>
      <xsl:choose>
        <xsl:when test="$match and $module != 'MailAdminGuide'"><!-- 
change the document identifier to match your 'current' document -->
          <xsl:element name="olink">
            <xsl:attribute name="targetdoc"><xsl:value-of 
select="$module"/></xsl:attribute>
            <xsl:attribute name="targetptr"><xsl:value-of 
select="$target"/></xsl:attribute>
          </xsl:element>
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="xref">
            <xsl:attribute name="linkend"><xsl:value-of 
select="$target"/></xsl:attribute>
            <xsl:attribute name="role"><xsl:value-of 
select="$role"/></xsl:attribute>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each><!-- end of context switch -->
  </xsl:template>

Please let me know if you find bugs or room for improvement. I'm no XSL 
expert.

Taro

To unsubscribe from this list, send a post to docbook-apps-unsubscribe@lists.oasis-open.org.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]