0

I have an XML file with a CALS-table which I want to import into an indesign. The problem is, that the actual table in indesign has some cell styles defined and indesign doesn't allow to add tags (and so styles) to a CALS-table (only indesign tables).

My xml looks like this

<table>
<tgroup cols="6">
<colspec colname="c1" colwidth="29pt"/>
<colspec colname="c2" colwidth="172pt"/>
<colspec colname="c3" colwidth="71pt"/>
<colspec colname="c4" colwidth="69pt"/>
<colspec colname="c5" colwidth="113pt"/>
<colspec colname="c6" colwidth="69pt"/>
<thead>
<row>
<entry align="left" colsep="0" valign="bottom">Tag</entry>
<entry align="left" colsep="0" valign="bottom">Datum</entry>
<entry align="left" colsep="0" valign="bottom">Zeit</entry>
<entry align="left" colsep="0" valign="bottom">Ort</entry>
<entry align="left" colsep="0" valign="bottom">Leitung</entry>
<entry align="left" colsep="0" valign="bottom">Kursnummer</entry>
</row>
</thead>
<tbody>
<row>
<entry colsep="0">Mi</entry>
<entry colsep="0" valign="bottom">15.03.2012, 16.03.2012, 17.03.2012</entry>
<entry colsep="0" valign="bottom">10:15 - 11:45</entry>
<entry colsep="0" valign="bottom">someplace</entry>
<entry colsep="0" valign="bottom">some Name</entry>
<entry colsep="0" valign="bottom">ABC-DE-12</entry>
</row>
<row>
<entry colsep="0">Mi</entry>
<entry colsep="0" valign="bottom">15.06.2012, 16.06.2012, 17.06.2012</entry>
<entry colsep="0" valign="bottom">09:15 - 10:45</entry>
<entry colsep="0" valign="bottom">otherplace</entry>
<entry colsep="0" valign="bottom">other Name</entry>
<entry colsep="0" valign="bottom">XYZ-U-K-13</entry>
</row>
</tbody>
</tgroup>
</table>

When I import this I get a standard table with some black borders around and the font-size is wrong. I have also some more details added in the cellstyles (i.e. a coloured border-bottom 0.5pt). It'd be great if I could do all the styling in the indesign. I don't really like it to set colwidth in the xml but I understand why I have to do this...

I heard there where solutions with xslt or idml but I'm new to both... Is there an easy solution to add the cell styles (one for <tbody> and one for <thead>)?

Same questions goes for table styles (don't need this yet, but maybe I need it later...)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dollique
  • 952
  • 2
  • 10
  • 29
  • Can you add an example of the original XML and an example of what the output should look like? It should be easy with XSLT. – Daniel Haley Dec 15 '12 at 13:54
  • I added the xml and I described a little bit of my needs. Hope you can give me a little XSLT example code. – Dollique Dec 17 '12 at 08:03

2 Answers2

2

For anyone still looking - there is a separate aid5: namespace that allows cellstyles. You can combine 2 namespaces in the table tag attributes as shown in the examples below to take advantage of aid: and aid5: attributes... also to use table styles, you simply "name" your table tag something unique and use that name to map your tags to styles in the Indesign file. Named table tags and misc. named tags must be mapped manually (to table styles for tables, or character styles for misc. other formatting), while cellstyle, pstyle (paragraph styles) and cstyle (character style) attributes within a tag, map themselves as long as you have a paragraph, cell, or character style with the exact same case-sensitive name. If you can have a placeholder table (with a header row and one body row) in your Indesign template, you can forego using widths. Any pre-populated cells (like the header row) can be skipped by using a self closing tag as shown below. Lastly, if you don't know how many rows you will have, simply make each repeating row its own complete table with just one row. Not ideal, and in my case we used a variable to populate the aid:trows attribute instead. The front end that was feeding the data calculated row counts for us (edits made, fixed wrong column count and added indenting).

    <!-- table with widths declared -->
    <myTableStyleName xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="3" aid:tcols="2">
        <Cell aid:table="cell" aid:ccolwidth="200" aid:theader="" aid:crows="1" aid:ccols="1" aid5:cellstyle="headerCell" aid:pstyle="headerCellP">column one header</Cell>
        <Cell aid:table="cell" aid:ccolwidth="200" aid:theader="" aid:crows="1" aid:ccols="1" aid5:cellstyle="headerCell" aid:pstyle="headerCellP">column two header</Cell>
        <Cell aid:table="cell" aid:ccolwidth="200" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphAwayGame">row 1 col 1</Cell>
        <Cell aid:table="cell" aid:ccolwidth="200" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphHomeGame">row 1 col 2 <myCharStyle>WE WON!</myCharStyle></Cell>
        <Cell aid:table="cell" aid:ccolwidth="200" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphAwayGame">row 2 col 1</Cell>
        <Cell aid:table="cell" aid:ccolwidth="200" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphHomeGame">row 2 col 2</Cell>
    </myTableStyleName>

    <!-- table data populating starter rows in Indesign, no widths needed -->
    <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="3" aid:tcols="2">
        <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1" aid5:cellstyle="headerCell" aid:pstyle="headerCellP"/>
        <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1" aid5:cellstyle="headerCell" aid:pstyle="headerCellP"/>
        <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphAwayGame">row 1 col 1</Cell>
        <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphHomeGame">row 1 col 2</Cell>
        <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphAwayGame">row 2 col 1</Cell>
        <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid5:cellstyle="bodyCellA" aid:pstyle="paragraphHomeGame">row 2 col 2</Cell>
    </Table>
0
  1. You have to design the look of your table in InDesign with some sample data
  2. Tag the content of your sample table
  3. Export your sample table using the XML-Export function
  4. Based on the sample xml-data you can write a Transformation for your cals-table
  5. Import the Cals data applying the indesign xslt option

If you are not so experienced, then probably the most tricky part will be to provide the correct namespace to the table tag and it's attributes:

xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"

Here is an example XSLT Stylesheet to transform your data to an indesign table with cellstyles:

<xsl:stylesheet 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/"
exclude-result-prefixes="xs">

<xsl:output indent="yes" encoding="UTF-8" standalone="yes" />
<xsl:strip-space elements="table thead tbody row entry" />

<xsl:variable name="tcols"><xsl:value-of select="table/tgroup/@cols" /></xsl:variable>
<xsl:variable name="trows"><xsl:value-of select="ceiling ( ( count(table/tgroup/thead/row/entry) + count(table/tgroup/tbody/row/entry) ) div $tcols )" /></xsl:variable>

<xsl:template match="/">
    <xsl:processing-instruction name="whitespace-handling">
        <xsl:text>use-tags</xsl:text>
    </xsl:processing-instruction>
    <table aid:table="table" aid:trows="{$trows}" aid:tcols="{$tcols}">
        <xsl:apply-templates select="table/tgroup/thead/row" />
        <xsl:apply-templates select="table/tgroup/tbody/row" />    
    </table>
</xsl:template>

<xsl:template match="thead/row/entry | tbody/row/entry">
    <cell aid:table="cell" aid:crows="1" aid:ccols="1">
        <xsl:if test="ancestor::thead">
            <xsl:attribute name="aid:theader" />
        </xsl:if>
        <!-- Here your style-definition based on something  -->
        <xsl:attribute name="aid5:cellstyle"><xsl:text>mycellstyle</xsl:text></xsl:attribute>
        <xsl:attribute name="aid:ccolwidth">
            <xsl:call-template name="getcolwidth">
                <xsl:with-param name="position">
                    <xsl:value-of select="position()" />
                </xsl:with-param>
            </xsl:call-template>
        </xsl:attribute>
        <xsl:value-of select="." />
    </cell>
</xsl:template>

<xsl:template name="getcolwidth">
    <xsl:param name="position" />
    <xsl:for-each select="/table/tgroup/colspec">
        <xsl:if test="position() = $position">
            <xsl:value-of select="substring-before(@colwidth, 'pt')" />
        </xsl:if>
    </xsl:for-each>
</xsl:template>

eisenstein
  • 31
  • 3
  • If I export the table with tagging the data I get an InDesign-Table, not a CALS-Table. But I need a CALS-Table. When I just tag the Element I get a CALS-Table but no xmlns! Isn't the attribute you posted reffering to an InDesign-table and not a CALS one (I don't know `:aid` in CALS-tables...)? – Dollique Dec 20 '12 at 08:21
  • You're right, aid is the Adobe Namespace. CALS-Tables do not have a cellstyle attribute. There is a tabstyle and tgroupstyle attribute, but as much I know, InDesign doesn't support those. Why do you need CALS-Tables, what is your workflow? – eisenstein Dec 21 '12 at 04:26
  • I need CALS-Table because I generate an XML with Coldfusion and ``. I had an error when using the `:aid` attribute, so I thought ColdFusion doesn't support this. I don't know if this is a problem that can be solved... Thanks for the xslt-example anyway. Maybe I can use this later. – Dollique Dec 21 '12 at 07:27