Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:49+00:00 2026-05-26T20:11:49+00:00

I need to make a CSV-parser using XSLT 1.0. I have tried a recursive

  • 0

I need to make a CSV-parser using XSLT 1.0. I have tried a recursive approach, but I can’t seem to match the line endrings, so the input to the printLine-template is always empty.

<xsl:template match="/">
  <xsl:call-template name="printLine">
    <xsl:with-param name="line">
      <xsl:value-of select="substring-before(//csvText, '\n')"/>
    </xsl:with-param>
    <xsl:with-param name="remaining">
      <xsl:value-of select="substring-after(//csvText, '\n')"/>
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="printLine">
<xsl:param name="line"/>
<xsl:param name="remaining"/>
    <xsl:value-of select="$line"/><br />
    <xsl:if test="remaining != ''">
    <xsl:call-template name="printLine">
      <xsl:with-param name="line">
        <xsl:value-of select="substring-before($remaining, '\n')"/>
      </xsl:with-param>
      <xsl:with-param name="remaining">
        <xsl:value-of select="substring-after($remaining, '\n')"/>
      </xsl:with-param>
    </xsl:call-template>
    </xsl:if>
</xsl:template>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:11:50+00:00Added an answer on May 26, 2026 at 8:11 pm

    I found a solution to this:

    <xsl:variable name="ls"><xsl:text>
    </xsl:text></xsl:variable>
    <xsl:variable name="fs"><xsl:text>  </xsl:text></xsl:variable>
    
    <xsl:template match="/">
      <xsl:call-template name="printLine">
        <xsl:with-param name="line" select="substring-before(//csvText, $ls)"/>
        <xsl:with-param name="remaining" select="substring-after(//csvText, $ls)"/>
      </xsl:call-template>
    </xsl:template>
    
    <xsl:template name="printLine">
    <xsl:param name="line"/>
    <xsl:param name="remaining"/>
        <xsl:call-template name="printFields">
            <xsl:with-param name="line" select="$line"/>
        </xsl:call-template>
        <xsl:if test="$remaining != ''">
        <xsl:call-template name="printLine">
          <xsl:with-param name="line" select="substring-before($remaining, $ls)"/>
          <xsl:with-param name="remaining" select="substring-after($remaining, $ls)"/>
        </xsl:call-template>
        </xsl:if>
    </xsl:template>
    
    <xsl:template name="printFields">
        <xsl:param name="line"/>
        <!-- render each line and access each field using the getFieldByIndex-template. Example: -->
        <div>
            <h3>
                <xsl:call-template name="getFieldByIndex">
                    <xsl:with-param name="index" select="1"/>
                    <xsl:with-param name="line" select="$line"/>
                </xsl:call-template>
            </h3>
            <p>
                <xsl:call-template name="getFieldByIndex">
                    <xsl:with-param name="index" select="4"/>
                    <xsl:with-param name="line" select="$line"/>
                </xsl:call-template>
            </p>
        </div>
    </xsl:template>
    
    <xsl:template name="getFieldByIndex">
        <xsl:param name="index"/>
        <xsl:param name="line"/>
        <xsl:choose>
            <xsl:when test="$index > 0">
                <xsl:call-template name="getFieldByIndex">
                    <xsl:with-param name="index" select="$index -1"/>
                    <xsl:with-param name="line" select="substring-after($line, $fs)"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring-before($line,$fs)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    

    The line- and field separators are stored in the ls and fs variables. This example traverses a tab-serparated file. The printFields-template has to be customized for each use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file I need to cleanup. It contains 13 fields, but
I have a crystal report file I need make a tiny edit in. It
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I need to make sure that user can run only one instance of my
I have some CSV files that I need uploaded to a site I'm writing
I have read through the solutions to similar problems, but they all seem to
I have a csv file to read, but in one column there are some
I have a CSV of file of data that I can load in R
We have a CSV uploader where users can upload a CSV file filled with
I have csv file having some address data mostly in Finnish language. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.