Jebaseelan Ravi
Jebaseelan Ravi

Reputation: 793

Convert csv into xml using XLST transformation?

This is my input csv file

JobID
123
345
234
121
2390

I want the ouput xml file in the below format using XLST transformation

<jobs>
    <job>
        <jobid>123</<jobid>
    </job>
    <job>
        <jobid>345</<jobid>
    </job>
    <job>
        <jobid>234</<jobid>
    </job>
    <job>
        <jobid>121</<jobid>
    </job>
    <job>
        <jobid>2390</<jobid>
    </job>
</jobs>

Can anyone please help me to solve the sbove problem with some code snippet?

thanks in advance

Upvotes: 0

Views: 86

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

In XSLT 3.0 with expand-text="yes" this is simply:

<jobs>
  <xsl:for-each select="tail(unparsed-text-lines('input.txt'))">
    <job><jobid>{.}</jobid></job>
  </xsl:for-each>
</jobs>

Upvotes: 2

Related Questions