Skip to main content

Transform Eclipse navigation files to DITA navigation files

Stylesheet addresses migration task that conversion tools do not automate

Loretta Hicks (hicks@us.ibm.com), Advisory Software Engineer, IBM Corporation
Most recently, Loretta has been part of a team that develops demos for Service-Oriented Architecture (SOA) and Business Process Management (BPM). This article is based on some of the lessons learned while developing those demos.

Summary:  For Eclipse help plug-in developers, navigation files (TOC files) represent a considerable investment of effort. If you decide to convert the source files for an Eclipse plug-in to Darwin Information Typing Architecture (DITA) files, then you'll find tools to assist you with converting the HTML files, but the readily available tools do not support conversion of TOC files to DITA map files. This article provides an XSLT stylesheet for converting Eclipse TOC files to DITA map files.

Date:  06 Apr 2005
Level:  Intermediate
Activity:  1845 views

This article addresses one task in the migration process that the conversion tools do not automate: Converting Eclipse TOC files to DITA map files. It does not discuss the reasons for converting HTML files to DITA format; other developerWorks articles and resources on the OASIS DITA Web site explain those advantages (see Resources). This article compares the elements of two XML-based navigation files and then uses sample master TOC and subordinate TOC files to illustrate the transformations to DITA. The article also provides instructions for using the XSLT stylesheet to convert your own Eclipse TOC files.

Fill the void in current tools

If you need to convert an Eclipse help plug-in to DITA, you can find tools for transforming your HTML files to XHMTL, and tools for converting the XHTML files to DITA. (See Resources for articles that describe such conversions.) Although most of the files in an Eclipse help plug-in are usually HTML, the Eclipse TOC file represents a major investment of design and development time. Several factors depend on the TOC file, including the information architecture, the contents of the search database, and the visibility of key topics. If you have invested heavily in your TOC files and the files work the way you want them to, you will not want to risk manually converting the files to DITA map files -- but good luck finding a conversion tool that handles that task. After not finding such a tool, I decided to write an XSLT stylesheet to convert my files.


Compare the Eclipse TOC to the DITA map

Eclipse TOC files and DITA map files are both XML files that describe the navigation for a collection of topics. You'll find similarities and differences between the two types of files; for each valid element or attribute in an Eclipse TOC file, Table 1 identifies the corresponding element or attribute in a DITA map file. The attributes for each TOC element are listed after the element.


Table 1. Element-by-element comparison of Eclipse TOC to DITA map
TOC element or attributeMap element or attributeComments
<toc><map>These are the root elements of the document.
link_toanchorrefThese attributes refer to an insertion point (anchor) in another topic hierarchy (a TOC or a DITA map file). This topic hierarchy is integrated with the other topic hierarchy at the insertion point. This is known as bottom-up integration.
labeltitleThe label attribute is required for the <toc> element.
topic<topicref>The first <topicref> element in the DITA map is used to preserve the topic attribute of the <toc> element in the Eclipse TOC file. The value of the topic attribute is used to set the value of the href attribute of <topicref>. The print and toc attributes of the <topicref> element are set to "no."
<topic><topicref>If the <topic> element does not have an href attribute, then you can also transform the <topic> element to a <topichead> element.
labelnavtitleThe label attribute is required for the <topic> element.
hrefhrefThe value of the href attribute of the <topic> element is used to set the value of the href attribute of the <topicref> element.
<anchor><anchor>These elements define an insertion point which other topic hierarchies can link to (the link_to attribute of the <toc> element) or reference (the anchorref attribute of the <map> element).
ididThe id attribute is required for the <anchor> element.
<link><navref>These elements refer to another topic hierarchy. The other topic hierarchy is integrated with this topic hierarchy at this insertion point. This is known as top-down integration.
tocmaprefThe toc attribute is required for the <topic> element.

In the table, you can see that some elements are identical (such as <anchor>) or very similar. The similarities certainly made it easier for me to create an XSLT stylesheet to convert a TOC file to a DITA map file.

The remaining sections of this article describe the transformation of a set of sample TOC files to DITA map files. If you want to examine the sample files more closely as you read, download and extract the files in the root directory of the archive file x-ecldita-toc2dita.zip. (See Download for a link to the ZIP file.)

The download archive includes the sample TOC files, the corresponding DITA map files, and the XSLT stylesheet that's used to transform the TOC files. You can use a Web browser, an XML editor, or a text editor to view the TOC files. To view the DITA map files (extension .ditamap), you will need the IBM ID Workbench or the public DITA toolkit that is listed under Resources.

The plugins.zip file inside the x-ecldita-toc2dita.zip file contains the Eclipse TOC files from the root directory, packaged in two Eclipse plug-ins that you can install on an Eclipse help server.


Transform master TOC files

In many cases, the navigation for an Eclipse-based help system consists of multiple TOC files that are integrated through a central master TOC file. The master file can contain any combination of the following types of elements:

  • Topics (each specified by a <topic> element)
  • Links to other TOC files that already exist (top-down integration)
  • Anchors for extending the master TOC in the future (bottom-up integration)

Of course, the Eclipse help system does not require a master TOC file, but having one is definitely convenient when multiple content providers must work in parallel to develop a help system. Master TOC files are also essential when portions of the help system are installed at different times, such as a base product that can be upgraded by installing features. If it is necessary to integrate the feature help content with the base help system, then a master TOC file is essential.

In the download archive, the master TOC file is mastertoc.xml. Figure 1 shows the mastertoc.xml file beside a screenshot of how the integrated TOC files render in an Eclipse help browser. The master TOC file:

  • Contributes the root collection labeled "Administration Central" and references a content file that is displayed when the user clicks the root collection
  • Links to the subordinate collection (toca.xml)
  • Provides an anchor for extending the master TOC in the future
  • Contains a topic that provides notices to the user

Figure 1. Sections of the TOC from mastertoc.xml
Navigation entries from mastertoc.xml

When the master TOC is transformed to a DITA map file using the XSLT stylesheet (toc2dita_adv.xsl in the x-ecldita-toc2dita.zip file), the output file looks like Listing 1.


Listing 1. The transformed mastertoc.xml file (mastertoc.ditamap)
 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE map PUBLIC "-//IBM//DTD DITA Map//EN" "..\dtd\map.dtd">
<map title="Administration Central">
  <topicref navtitle="Administration Central" 
    href="admin_central.dita" print="no" toc="no"/> 
  <topicref navtitle="Console Basics" href="console_basics.dita"> 
     <navref mapref="toca.ditamap"/>
  </topicref> 
<anchor id="anchor_id"/>
<topicref navtitle="Notices" href="reference/notices.dita"/> 
</map> 

Of course, the sample master TOC is simplistic, but more complex master TOC files are just repetitions of the basic elements in the sample file. The XSLT stylesheet can handle complex TOC files, and it can process TOC files that reference file types other than HTML. The latest Eclipse technology supports rendering source files that are JavaServer Pages. So the XSLT stylesheet can handle the .jsp extension as well as .pdf, .gif, .htm, and .html.


Transform subordinate TOC files

This section focuses on two examples of subordinate TOC files: files that the master TOC links to and files that the master TOC provides an anchor for. In the archive file, the subordinate TOC files are toca.xml and tocb.xml.

The toca.xml file is integrated with the master TOC through the <link> element which explicitly references toca.xml, assigns a label for the collection ("Console Basics"), and references a topic file that is displayed when the user clicks the collection label. Associating a topic file with the collection is not required; in such cases, the href attribute is not specified. Because the linking involves specific information about the subordinate TOC, that type of linking can only be done when the TOC file already exists or when the developer can trust that it will exist when the Eclipse plug-in for the master TOC file is installed. Figure 2 shows the contents of the toca.xml file on the right, and a view of how the content is displayed in the Eclipse help browser on the left.


Figure 2. Sections of the TOC from toca.xml
Navigation entries from toca.xml

In contrast to the toca.xml file, the tocb.xml file is integrated with the master TOC through the <anchor>. If the designer of the master TOC anticipates a future need to integrate another TOC file, the developer can add an anchor in the desired point of the master TOC. The future TOC file will reference that anchor. Multiple anchors are permitted, but only one TOC in the installation can reference a specific anchor. In tocb.xml, the link_to attribute of the <toc> element points to the anchor in the master TOC. Figure 3 shows the contents of the tocb.xml file on the right, and a view of how the content is displayed in the Eclipse help browser on the left.


Figure 3. Sections of the TOC from tocb.xml
Navigation entries from tocb.xml

Notice that the value of the link_to attribute is the relative URL of the master TOC file concatenated with the number sign (#) and the value of the id attribute of the <anchor> element. Because the tocb.xml file and the mastertoc.xml file are in separate Eclipse plug-ins, the relative URL contains the plug-in name for the master TOC. Figure 4 and Figure 5 show the directories for the two plug-ins: com.mycompany.plugin.doc (which contains mastertoc.xml and toca.xml) and com.mycompany.plugin.adv.doc (which contains tocb.xml).


Figure 4. The com.mycompany.plugin.doc directory
Sample plug-in com.mycompany.plugin.doc

Figure 5. The com.mycompany.plugin.adv.doc directory
Sample plug-in com.mycompany.plugin.adv.doc

When you transform tocb.xml to a DITA map file using the XSLT stylesheet in the x-ecldita-toc2dita.zip file, the output file looks like Listing 2. Notice that the link_to attribute in the TOC file transforms to an anchorref attribute in the map file.


Listing 2. The transformed tocb.xml file (tocb.ditamap)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//IBM//DTD DITA Map//EN" "..\dtd\map.dtd"> 
<map title="Advanced" 
  anchorref="../com.mycompany.plugin.doc/mastertoc.ditamap#anchor_id"> 
  <topicref navtitle="Advanced topics" href="advanced.dita">
    <topicref navtitle="Adding resources" href="tasks/adding_res.dita"/>
    <topicref navtitle="Removing resources" href="tasks/removing_res.dita"/>
  </topicref>
</map>


Transform your TOC files

You've seen the transformation of the samples file. Now, it's time to try transforming your own Eclipse TOC files. Here are the steps for setting up your system and running the transformation:

  1. Download the archive x-ecldita-toc2dita.zip if you have not already done so. See Download near the end of this article.
  2. Use PKZip, WinZip, or a similar tool to extract the files.
  3. Create a folder to use as your transformation work area.
  4. Copy the toc2dita_adv.xsl file from the x-ecldita-toc2dita.zip file to your work folder.
  5. Copy your Eclipse TOC files to the same folder.
  6. If you do not already have a copy of an XSLT stylesheet processor, obtain a copy. For example, to obtain the Apache Xalan processor, visit Apache.org (see Resources). The Xalan package is available as C++ code and as Java code. The Java package is easier for novices to use.
  7. If you downloaded the Xalan-Java package, you will also need a Java Development Kit (JDK) because you must use the java command to run the processor class. If you have Rational Application Developer, WebSphere Application Server, or a similar Java-based application, you can use the JDK included with those applications. Otherwise, download a JDK from the Sun Developer's Site (see Resources).
  8. Follow the instructions provided with the XSLT processor to transform each of your Eclipse TOC files. In the command, specify that the toc2dita_adv.xsl file is the XSLT stylesheet and that the output file extension is .ditamap. Here is an example of the command for using Xalan-Java to transform a TOC file.
 
java -classpath 
  c:\jdk142\lib\j2ee.jar;c:\xalan_dir\xalan.jar org.apache.xalan.xslt.Process 
  -IN toc.xml -XSL toc2dita_adv.xsl -OUT toc.ditamap


Summary

When you migrate Eclipse help plug-ins to DITA format, you do not have to manually convert Eclipse TOC files to DITA map files. XSLT enables an easy, automated method to make this conversion, which reduces the risk of error and speeds the migration process. The download for this article provides an XSLT stylesheet for such transformations.

This article only addressed converting TOC files to DITA map files. In some cases, DITA maplists would be appropriate. In some cases, newer features of the OASIS DITA 1.0 specification (the "ditamap" format option) would be appropriate.



Download

DescriptionNameSizeDownload method
Code sample for articlex-ecldita-toc2dita.zip11 KB HTTP

Information about download methods


Resources

About the author

Most recently, Loretta has been part of a team that develops demos for Service-Oriented Architecture (SOA) and Business Process Management (BPM). This article is based on some of the lessons learned while developing those demos.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Open source
ArticleID=58455
ArticleTitle=Transform Eclipse navigation files to DITA navigation files
publish-date=04062005
author1-email=hicks@us.ibm.com
author1-email-cc=dwxed@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers