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 8065891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:48:41+00:00 2026-06-05T11:48:41+00:00

I have some code that loads in an xml file and applies an XSLT

  • 0

I have some code that loads in an xml file and applies an XSLT to it using “XslCompiledTransform”. I now need to change the code as the input file may not be XML, it could also be a CSV file. I have an XSLT that will convert the CSV to the format I want but it uses a hardcoded path. The problem I have is that the input filename will change so can I use a widecard in the name? Secondly, in code can I pass in the file as a string to an XSLT object and have the result fall out the bottom? I’ve been doing some googling and not found any code to do this. Is it even possible?

Here is the XSLT I am using. Not the hardcoded path and filename.

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="fn"
    exclude-result-prefixes="xs fn">

<xsl:output indent="yes" encoding="US-ASCII"/>

<xsl:param name="pathToCSV" select="'file:///C:/Downloads/inputcsv.csv'"/>

<xsl:function name="fn:getTokens" as="xs:string+">
    <xsl:param name="str" as="xs:string"/>
        <xsl:analyze-string select="concat($str, ',')" regex='(("[^"]*")+|[^,]*),'>
            <xsl:matching-substring>
                <xsl:sequence select='replace(regex-group(1), "^""|""$|("")""", "$1")'/>
            </xsl:matching-substring>
        </xsl:analyze-string>
</xsl:function>

<xsl:template match="/" name="main">
    <xsl:choose>
        <xsl:when test="unparsed-text-available($pathToCSV)">
            <xsl:variable name="csv" select="unparsed-text($pathToCSV)"/>
            <xsl:variable name="lines" select="tokenize($csv, '&#xD;')" as="xs:string+"/>
            <xsl:variable name="elemNames" select="fn:getTokens($lines[1])" as="xs:string+"/>
            <root>
                <xsl:for-each select="$lines[position() > 0]">
                    <row>
                        <xsl:variable name="lineItems" select="fn:getTokens(.)" as="xs:string+"/>

                        <xsl:for-each select="$elemNames">
                            <xsl:variable name="pos" select="position()"/>
                            <column>
                                <xsl:value-of select="$lineItems[$pos]"/>
                            </column>
                        </xsl:for-each>
                    </row>
                </xsl:for-each>
            </root>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text>Cannot locate : </xsl:text><xsl:value-of select="$pathToCSV"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>
  • 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-06-05T11:48:42+00:00Added an answer on June 5, 2026 at 11:48 am

    Well XslCompiledTransform is an XSLT 1.0 processor so using XSLT 2.0 features like unparsed-text is not possible with XslCompiledTransform, you need to use Saxon 9 or XmlPrime or AltovaXML for XSLT 2.0.

    Then you can pass in a parameter to your posted stylesheet as it has a global xsl:param named pathToCSV, how you pass in that parameter depends on the API of the XSLT processor you want to use (or on its command line parameters if you simply want to execute the stylesheet from the command line).

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

Sidebar

Related Questions

I have some code that parses an xml file using XDocument . It retrieves
I have written some code that loads an XML document using an XmlDocument object
I have some code that loads an image file off the web and puts
I have an xml file with a node that contains some c# code. <Script
I have some code that is using SyncEnumerator. As you can see here ,
I have an XML file that specifies the image files that I need to
I have a site that loads in a XML file which tells where to
I have some code which fetches an XML file from a URL and then
I have a script that loads info from external XML file and inserts it
I have some code that sets up a dictionary with some defualt values for

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.