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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:21:38+00:00 2026-06-11T21:21:38+00:00

I have the following test code that tries to convert a cvs file to

  • 0

I have the following test code that tries to convert a cvs file to xml. The problem I have is that sometimes it will run and other times it fails with the following error:

The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.

Here is the code:

        XsltCompiler compiler = null;
        try
        {
            Processor processor = new Processor();
            compiler = processor.NewXsltCompiler();

            var sr = new StreamReader(@"c:\files\drop\csv-to-xml_v2.xslt");
            var xslt = sr.ReadToEnd();
            sr.Close();

            StringReader reader = new StringReader(xslt);

            XsltExecutable exec = compiler.Compile(reader);

            XsltTransformer transformer = exec.Load();

            transformer.InitialTemplate = new QName("", "main");

            var XmlResult = new DomDestination();

            transformer.Run(XmlResult);

            reader.Close();
        }
        catch (Exception ex)
        {
            var errMsg = ex.Message;
            var errList = compiler != null ? compiler.ErrorList : null;
        }

The XSLT is:

<?xml version="1.0"?>

<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:/Files/Drop/inputcsv1.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>

Can anyone see why sometimes it works and then for no reason it fails on the “transformer.Run(XmlResult)” line ? I am using c# 4, Visual Studio 2010 and Saxon 9 HE.

  • 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-11T21:21:40+00:00Added an answer on June 11, 2026 at 9:21 pm

    In the “otherwise” branch, you are creating a text node as a child of the document node. Because your destination is a DOM destination, this isn’t allowed. (It’s permitted in the XDM data model, but there is no way of representing this in a DOM).

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

Sidebar

Related Questions

I have the following code that applies a XSLT style Test.Xml.xslTransform = function(xml, xsl)
I have the following code that reads mac addresses from a file and tries
I have following code: //preparing DAO objects FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(test-context.xml); surveyDao =
I have the following code that tries to enumerate strings. #include <string> #include <iostream>
I have the following code that retrive json data and tries to parse it
I have the following test code use Data::Dumper; my $hash = { foo =>
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have the following code in test.sh: while getopts f:i: opt; do case $opt
I have the following code: class Test { public static void main(String[] args) {
I have the following code require 'test_helper' class ApplicationControllerTest < ActionController::TestCase test should display

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.