How to read csv file in Xslt to transform it into CDATA tag

3.1k views Asked by At

I want to write an XSLT that will read a CSV file and transform the data into CDATA tag

sample input file

Col1,Col2,Col3
apple,mango,orange

required output

<![CDATA[apple|mango|orange]]>
1

There are 1 answers

10
Michael Kay On BEST ANSWER

Something like this:

<xsl:stylesheet version="2.0"...>

<xsl:template name="main">
  <out>
    <xsl:for-each select="tokenize(unparsed-text('input.csv'), '\n')">
    <line>
      <xsl:value-of select="tokenize(., ',')" separator="|"/>
    </line>
    </xsl:for-each>
  </out>
</xsl:template>

<xsl:output cdata-section-elements="line"/>

</xsl:stylesheet>