Page 1 of 1

Table import in DITA format

Posted: Mon Feb 03, 2014 3:30 pm
by Frank Ralf
We want to import text tables like the following into DITA:

Code: Select all


Type | Value | Description
Lead | Low | Starting point for alchemists.
Gold | High | The alchemist’s goal.
The File > Import > Text File function works fine, but gives us the following:

Code: Select all


<root>
<row>
<Type>Lead</Type>
<Value>Low</Value>
<Description>Starting point for alchemists.</Description>
</row>
<row>
<Type>Gold</Type>
<Value>High</Value>
<Description>The alchemist’s goal.</Description>
</row>
</root>
Whereas in DITA we would prefer something like this:

Code: Select all


<table>
<row>
<entry colname="Type">Lead</entry>
<entry colname="Value">Low</entry>
<entry colname="Description">Starting point for alchemists.</entry>
</row>
<row>
<entry colname="Type">Gold</entry>
<entry colname="Value">High</entry>
<entry colname="Description">The alchemist’s goal.</entry>
</row>
</table>
Can this be configured using some settings or do we have to use a XSLT transformation?

TIA
Frank

Re: Table import in DITA format

Posted: Mon Feb 03, 2014 3:39 pm
by sorin_ristache
Hello,

All the possible configuration options are available in the Import dialog box. As you can see there you can select between child element in the <row> element and attribute of the <row> element, but you can't add an attribute to the child element of <row>. You will need a simple XSLT transformation.


Regards,
Sorin

Re: Table import in DITA format

Posted: Mon Feb 03, 2014 5:05 pm
by Frank Ralf
Thanks for the quick reply. That's what I suspected.

Re: Table import in DITA format

Posted: Mon Feb 03, 2014 6:12 pm
by Frank Ralf
JFTR here's the XSLT I'm using:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="root">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>

<xsl:template match="row">
<row>
<xsl:apply-templates/>
</row>
</xsl:template>

<xsl:template match="*">
<entry>
<xsl:attribute name="colname">
<xsl:value-of select="local-name()"/>
</xsl:attribute>
<xsl:value-of select="."/>
</entry>
</xsl:template>

</xsl:stylesheet>