Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get Coldfusion XSLT 'contains' function to work?
    text
    copied!<p>I am trying to convert xml dumps similar to this one</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;report&gt; &lt;report_header&gt; &lt;c1&gt;desc&lt;/c1&gt; &lt;c2&gt;prname&lt;/c2&gt; &lt;c3&gt;prnum&lt;/c3&gt; &lt;c4&gt;cdate&lt;/c4&gt; &lt;c5&gt;phase&lt;/c5&gt; &lt;c6&gt;stype&lt;/c6&gt; &lt;c7&gt;status&lt;/c7&gt; &lt;c8&gt;parent&lt;/c8&gt; &lt;c9&gt;location&lt;/c9&gt; &lt;/report_header&gt; &lt;report_row&gt; &lt;c1&gt;&lt;/c1&gt; &lt;c2&gt;IT Project Message Validation&lt;/c2&gt; &lt;c3&gt;IT-0000021&lt;/c3&gt; &lt;c4&gt;12/14/2010 09:56 AM&lt;/c4&gt; &lt;c5&gt;Preparation&lt;/c5&gt; &lt;c6&gt;IT Projects&lt;/c6&gt; &lt;c7&gt;Active&lt;/c7&gt; &lt;c8&gt;IT&lt;/c8&gt; &lt;c9&gt;/IT/BIOMED&lt;/c9&gt; &lt;/report_row&gt; &lt;report_row&gt; &lt;c1&gt;&lt;/c1&gt; &lt;c2&gt;David, Michael John Morning QA Test&lt;/c2&gt; &lt;c3&gt;IT-0000020&lt;/c3&gt; &lt;c4&gt;12/14/2010 08:12 AM&lt;/c4&gt; &lt;c5&gt;Preparation&lt;/c5&gt; &lt;c6&gt;IT Projects&lt;/c6&gt; &lt;c7&gt;Active&lt;/c7&gt; &lt;c8&gt;IT&lt;/c8&gt; &lt;c9&gt;/IT/BIOMED&lt;/c9&gt; &lt;/report_row&gt; &lt;/report&gt; </code></pre> <p>with the xslt below, to csv. Unfortunately the contains function does not work.</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="text"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="report"&gt; &lt;xsl:apply-templates select="report_header"/&gt; &lt;xsl:apply-templates select="report_row"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="report_header"&gt; &lt;xsl:for-each select="*"&gt; &lt;xsl:value-of select="."/&gt; &lt;xsl:if test="position() != last()"&gt; &lt;xsl:value-of select="','"/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;xsl:text&gt; &lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="report_row"&gt; &lt;xsl:param name="value" /&gt; &lt;xsl:for-each select="*"&gt; &lt;xsl:value-of select="$value" /&gt; &lt;xsl:if test="(contains($value,','))"&gt; &lt;xsl:text&gt;"&lt;/xsl:text&gt;&lt;xsl:value-of select="."/&gt;&lt;xsl:text&gt;"&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;xsl:if test="not(contains($value,','))"&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:if&gt; &lt;xsl:if test="position() != last()"&gt; &lt;xsl:value-of select="','"/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;xsl:if test="position() != last()"&gt; &lt;xsl:text&gt; &lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I get the following dump. I expected the qualifiers around the prname column on the second row.</p> <pre><code>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 </code></pre> <p>I have only used the coldfusion xmltransform function to test it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload