Table import in DITA format

Post here questions and problems related to editing and publishing DITA content.
Frank Ralf
Posts: 485
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Table import in DITA format

Post 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
Frank Ralf
parson AG
www.parson-europe.com
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Table import in DITA format

Post 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
Frank Ralf
Posts: 485
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: Table import in DITA format

Post by Frank Ralf »

Thanks for the quick reply. That's what I suspected.
Frank Ralf
parson AG
www.parson-europe.com
Frank Ralf
Posts: 485
Joined: Thu Jan 23, 2014 2:29 pm
Location: Hamburg
Contact:

Re: Table import in DITA format

Post 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>
Frank Ralf
parson AG
www.parson-europe.com
Post Reply