Connecting Tech Pros Worldwide Forums | Help | Site Map

XSLT Table Transformation

Newbie
 
Join Date: Nov 2008
Posts: 11
#1: Mar 5 '09
Hello,
I have a series of xml tables that i should convert to html code -
Here is an Example:
Expand|Select|Wrap|Line Numbers
  1. <TABELLA data_mod="2008-10-30 12:20:59" id="2903" locale="it_IT" colonne="1" righe="2"
  2.             colonna_1="100%">
  3.             <grown>
  4.                 <TAB_2903>
  5.                     <story>
  6.                         <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table"
  7.                             aid:trows="2" aid:tcols="1" summary="NOCHANGE">
  8.                             <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  9.                                 larghezza="100%">
  10.                                 <_B>
  11.                                     <img_html href="file://./NOME_1.eps" proporzione_x="31"
  12.                                         id="50211557" proporzione_h="32" proporzione_w="32"
  13.                                         alkusetype="3"/>
  14.                                 </_B>
  15.                             </Cell>
  16.                             <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  17.                                 larghezza="100%">56733</Cell>
  18.                         </Table>
  19.                     </story>
  20.                 </TAB_2903>
  21.             </grown>
  22.         </TABELLA>
Every table has a unique ID like </TAB_2903>, </TAB_2904>, etc.
Can anyone help me with this problem?
Thanks to all in advance

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: Mar 5 '09

re: XSLT Table Transformation


what does your html code shall look like? (in other words: a table isn't a table isn't a table)

if you know that, you can "map" your xml data to these html elements/attributes using <xsl:template>. see XSLT @ w3schools
Newbie
 
Join Date: Nov 2008
Posts: 11
#3: Mar 8 '09

re: XSLT Table Transformation


Hello Dormilich,
the tables have to look like this:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <body>
  3.         <table>
  4.             <tr>
  5.                 <td>
  6.                     <img src="NOME_1.eps"/>
  7.                 </td>
  8.             </tr>
  9.             <tr>
  10.                 <td>56733</td>
  11.             </tr>
  12.         </table>
  13.     </body>
  14. </html>
But the problem here, is that every table has got a variable number of columns and rows, and the only reference to these seem to be aid:trows and aid:tcols (as a note, these tables are exported from Adobe Indesign).
I think that there would be some sort of recursive function to divide the cells by the values of tcols and trows, but I'm not able to do this.
I also attach other 2 tables so that you can better understand the problem:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Root>
  3.     <TABELLA data_mod="2008-10-30 12:20:59" id="2899" locale="it_IT" colonne="3" righe="2"
  4.         colonna_1="33%" colonna_2="33%" colonna_3="33%">
  5.         <grown>
  6.             <TAB_2899>
  7.                 <story>
  8.                     <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table"
  9.                         aid:trows="2" aid:tcols="3" summary="NOCHANGE">
  10.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  11.                             larghezza="33%">
  12.                             <_B>
  13.                                 <img_html href="file://./NOME_1.eps" proporzione_x="31"
  14.                                     id="50211557" proporzione_h="32" proporzione_w="32"
  15.                                     alkusetype="3"/>
  16.                             </_B>
  17.                         </Cell>
  18.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  19.                             larghezza="33%">
  20.                             <_centro>
  21.                                 <img_html href="file://./LUNGHEZZA_1.eps" proporzione_x="31"
  22.                                     id="50211532" proporzione_h="34" proporzione_w="55"
  23.                                     alkusetype="3"/>
  24.                             </_centro>
  25.                         </Cell>
  26.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  27.                             larghezza="33%">
  28.                             <img_html href="file://./TIPO_1.eps" proporzione_x="31" id="50211586"
  29.                                 proporzione_h="78" proporzione_w="79" alkusetype="3"/>
  30.                         </Cell>
  31.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  32.                             larghezza="33%">12613</Cell>
  33.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  34.                             larghezza="33%">130</Cell>
  35.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  36.                             larghezza="33%">ø25 - 1&quot;3/8&quot; Z6</Cell>
  37.                     </Table>
  38.                 </story>
  39.             </TAB_2899>
  40.         </grown>
  41.     </TABELLA>
  42.     <TABELLA data_mod="2008-10-30 12:20:58" id="2895" locale="it_IT" colonne="5" righe="2"
  43.         colonna_1="20%" colonna_2="20%" colonna_3="20%" colonna_4="20%" colonna_5="20%">
  44.         <grown>
  45.             <TAB_2895>
  46.                 <story>
  47.                     <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table"
  48.                         aid:trows="2" aid:tcols="5" summary="NOCHANGE">
  49.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  50.                             larghezza="20%">
  51.                             <_B>
  52.                                 <img_html href="file://./NOME_1.eps" proporzione_x="31"
  53.                                     id="50211557" proporzione_h="32" proporzione_w="32"
  54.                                     alkusetype="3"/>
  55.                             </_B>
  56.                         </Cell>
  57.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  58.                             larghezza="20%">
  59.                             <_centro>
  60.                                 <img_html href="file://./COPPIA CONTINUA_1.eps" proporzione_x="31"
  61.                                     id="50211518" proporzione_h="84" proporzione_w="85"
  62.                                     alkusetype="3"/>
  63.                             </_centro>
  64.                         </Cell>
  65.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  66.                             larghezza="20%">
  67.                             <_centro>
  68.                                 <img_html href="file://./RAPPORTO DI MOLTIPLICA_1.eps"
  69.                                     proporzione_x="31" id="50211574" proporzione_h="59"
  70.                                     proporzione_w="60" alkusetype="3"/>
  71.                             </_centro>
  72.                         </Cell>
  73.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  74.                             larghezza="20%">
  75.                             <img_html href="file://./MISURA A_1.eps" proporzione_x="31"
  76.                                 id="50211536" proporzione_h="57" proporzione_w="57" alkusetype="3"/>
  77.                         </Cell>
  78.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  79.                             larghezza="20%">
  80.                             <img_html href="file://./MISURA B_1.eps" proporzione_x="31"
  81.                                 id="50211538" proporzione_h="59" proporzione_w="60" alkusetype="3"/>
  82.                         </Cell>
  83.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  84.                             larghezza="20%">17644</Cell>
  85.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  86.                             larghezza="20%">900</Cell>
  87.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  88.                             larghezza="20%">3,1:1</Cell>
  89.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  90.                             larghezza="20%">35</Cell>
  91.                         <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="184"
  92.                             larghezza="20%">10</Cell>
  93.                     </Table>
  94.                 </story>
  95.             </TAB_2895>
  96.         </grown>
  97.     </TABELLA>
  98. </Root>
Please let me know if you find a solution to this.
Anyhow, thanks for your support
Filippo
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#4: Mar 10 '09

re: XSLT Table Transformation


I see, so your problem is that the cells just come one after each other?

Suggested solution is somewhat like the following:
Expand|Select|Wrap|Line Numbers
  1. put xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" in your stylesheet node.
  2.  
  3. <xsl:template match="Table">
  4.   <table>
  5.     <xsl:variable name="cols" select="aid:crows"/>
  6.     <xsl:for-each select="Cell[position() mod $cols = 1]"><!-- get each cell at the start of a row. -->
  7.       <tr><!-- get all cells in this row -->
  8.         <xsl:apply-templates select=".|following-sibling::Cell[position() &lt; $cols]"/> 
  9.       </tr>
  10.     <xsl:for-each>
  11.   </table>
  12. </xsl:template>
  13.  
Reply