-2

I have working in xml to html conversion. But the table is a typeset format. In between text tab space presented.

input format

15  30  35
12  40  65

Expected output

<table>
    <tr>
    <td>15</td>
    <td>30</td>
    <td>35</td>
  </tr>
    <tr>
    <td>12</td>
    <td>40</td>
    <td>65</td>
  </tr>
 </table> 

thanks in advance.

Mahesh
  • 27
  • 2
  • 5

1 Answers1

0

Assuming you have the tab separated data in some element (e.g. data is assumed to contain the tab separated data in below sample) and you use XSLT 3 you can use the tokenize function first to split of the data into lines mapped to rows of the table and then to split up each row into the cell data:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    expand-text="yes"
    version="3.0">
    
  <xsl:template match="data">
      <xsl:where-populated>
          <table>
              <xsl:apply-templates select="tokenize(., '\r?\n')" mode="row"/>
          </table>
      </xsl:where-populated>
  </xsl:template>
  
  <xsl:template match=".[. instance of xs:string]" mode="row">
      <tr>
          <xsl:apply-templates select="tokenize(., '\t')" mode="cell"/>
      </tr>
  </xsl:template>
  
  <xsl:template match=".[. instance of xs:string]" mode="cell">
      <td>{.}</td>
  </xsl:template>

https://xsltfiddle.liberty-development.net/jxDjimZ

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110