Home > Back-end >  Read CSV file in xslt stylesheet
Read CSV file in xslt stylesheet

Time:11-14

I'm trying to convert a csv file into a xml file with Saxon 9. But I have a problem when I try to check existence and read a csv file with the xslt functions: unparsed-text-available(), unparsed-text()

unparsed-text-available($pathToCSV)

CSV file is located in "C:/Dev/". function keeps on returning false.

Here is a part of the xlst:

<xsl:template match="/" name="main">
  <xsl:choose>
    <xsl:when test="unparsed-text-available($pathToCSV)">
        <xsl:variable name="csv" select="unparsed-text($pathToCSV)"/>                    
            ....
    </xsl:when>
    <xsl:otherwise>
        <xsl:text>Cannot locate : </xsl:text><xsl:value-of select="$pathToCSV"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

I want the xslt file to read the csv content and parse it.

CodePudding user response:

Since you're calling the XSLT from Java, it should be convenient to use the toURI method of java.io.File to generate a file: URI and pass that as your $pathToCSV stylesheet parameter.

  • Related