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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:25:02+00:00 2026-05-18T20:25:02+00:00

I am trying to convert xml dumps similar to this one <?xml version=1.0 encoding=UTF-8?>

  • 0

I am trying to convert xml dumps similar to this one

<?xml version="1.0" encoding="UTF-8"?>
<report>
    <report_header>
        <c1>desc</c1>
        <c2>prname</c2>
        <c3>prnum</c3>
        <c4>cdate</c4>
        <c5>phase</c5>
        <c6>stype</c6>
        <c7>status</c7>
        <c8>parent</c8>
        <c9>location</c9>
    </report_header>
    <report_row>
        <c1></c1>
        <c2>IT Project Message Validation</c2>
        <c3>IT-0000021</c3>
        <c4>12/14/2010 09:56 AM</c4>
        <c5>Preparation</c5>
        <c6>IT Projects</c6>
        <c7>Active</c7>
        <c8>IT</c8>
        <c9>/IT/BIOMED</c9>
    </report_row>
    <report_row>
        <c1></c1>
        <c2>David, Michael John Morning QA Test</c2>
        <c3>IT-0000020</c3>
        <c4>12/14/2010 08:12 AM</c4>
        <c5>Preparation</c5>
        <c6>IT Projects</c6>
        <c7>Active</c7>
        <c8>IT</c8>
        <c9>/IT/BIOMED</c9>
    </report_row>
</report>

with the xslt below, to csv. Unfortunately the contains function does not work.

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="report">
        <xsl:apply-templates select="report_header"/>
        <xsl:apply-templates select="report_row"/>
    </xsl:template>

    <xsl:template match="report_header">
        <xsl:for-each select="*">
            <xsl:value-of select="."/>
            <xsl:if test="position() != last()">
                <xsl:value-of select="','"/>
            </xsl:if>
        </xsl:for-each>
        <xsl:text>
        </xsl:text>
    </xsl:template>

    <xsl:template match="report_row">
        <xsl:param name="value" />
        <xsl:for-each select="*">
            <xsl:value-of select="$value" />
            <xsl:if test="(contains($value,','))">
                <xsl:text>"</xsl:text><xsl:value-of select="."/><xsl:text>"</xsl:text>
            </xsl:if>
            <xsl:if test="not(contains($value,','))">
                <xsl:value-of select="."/>
            </xsl:if>
            <xsl:if test="position() != last()">
                <xsl:value-of select="','"/>
            </xsl:if>
        </xsl:for-each>
        <xsl:if test="position() != last()">
            <xsl:text>
            </xsl:text>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

I get the following dump. I expected the qualifiers around the prname column on the second row.

desc,prname,prnum,cdate,phase,stype,status,parent,location
        ,IT Project Message Validation,IT-0000021,12/14/2010 09:56 AM,Preparation,IT Projects,Active,IT,/IT/BIOMED
            ,David, Michael John Morning QA Test,IT-0000020,12/14/2010 08:12 AM,Preparation,IT Projects,Active,IT,/IT/BIOMED

I have only used the coldfusion xmltransform function to test it.

  • 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-18T20:25:03+00:00Added an answer on May 18, 2026 at 8:25 pm

    I don’t think that contains() is your issue.

    The issue is that your report_row template has an <xsl:param name="value"/> that is never assigned a value. You have logic that is driven from that param, which never fires. Because $value is empty, it will never contain() , or any other character.

    You could get the desired behavior by adding a select attribute to the xsl:param:

      <xsl:template match="report_row">
            <xsl:param name="value" select="." />
    

    You could simplify your stylesheet and logic by making more of a “push” style, which can be easier to debug and maintain than “pull” style stylesheets that attempt to implement procedural logic in XSLT.

    Something like the following stylesheet achieve the same thing:

    <?xml version="1.0"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="/">
            <xsl:apply-templates select="*/report_header/*"/>
            <xsl:apply-templates select="*/report_row/*"/>
        </xsl:template>
    
        <!-- For all but the last item, apply templates for the content, then add a comma -->
        <xsl:template match="*[following-sibling::*]">
            <xsl:apply-templates/>
            <xsl:text>,</xsl:text>
        </xsl:template>
    
        <!-- If it's the last element in a group, add a newline char -->
        <xsl:template match="*[not(following-sibling::*)]">
           <xsl:apply-templates />
            <!--Line break-->
            <xsl:text>&#10;</xsl:text>
        </xsl:template>
    
        <!-- If any values contains a comma, wrap it in quotes -->
        <xsl:template match="text()[contains(.,',')]">
            <xsl:text>"</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>"</xsl:text>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Produces the following output:

    desc,prname,prnum,cdate,phase,stype,status,parent,location
    ,IT Project Message Validation,IT-0000021,12/14/2010 09:56 AM,Preparation,IT Projects,Active,IT,/IT/BIOMED
    ,"David, Michael John Morning QA Test",IT-0000020,12/14/2010 08:12 AM,Preparation,IT Projects,Active,IT,/IT/BIOMED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert xml dumps similar to this one <?xml version=1.0 encoding=UTF-8?>
I'm trying to convert an XML file to DBF. Right now I do this
I'm trying to convert a xml document from one format to another and while
I am trying to convert some xml into a json object using PHP. This
I am trying to convert an XML file to CSV, but the encoding of
I'm trying to convert a hash to a XML-string with this module XML::Hash::LX but
I'm trying to convert an XML file into the markup used by dokuwiki, using
I'm trying to convert some XML data coming from a CLOB to a XMLType
I'm trying to convert an XML document into a dataset that I can import
I am trying to convert an Xml String to XML DOM object using Xerces

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.