Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT comma separation of elements
    text
    copied!<p><strong>I have the following XML document:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;cars&gt; &lt;car&gt; &lt;entrydata columnnumber="4" name="Colour"&gt; &lt;text&gt;Red&lt;/text&gt; &lt;/entrydata&gt; &lt;/car&gt; &lt;car&gt; &lt;entrydata columnnumber="4" name="Colour"&gt; &lt;textlist&gt; &lt;text&gt;Yellow&lt;/text&gt; &lt;text&gt;Blue&lt;/text&gt; &lt;/textlist&gt; &lt;/entrydata&gt; &lt;/car&gt; &lt;/cars&gt; </code></pre> <p><strong>And the following XSLT stylesheet:</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com: xslt" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;records&gt; &lt;xsl:apply-templates select="//cars"/&gt; &lt;/records&gt; &lt;/xsl:template&gt; &lt;!--Top level template --&gt; &lt;xsl:template match="cars"&gt; &lt;!-- Loop through each document (viewentry) and apply create the rows for each one--&gt; &lt;xsl:for-each select="car"&gt; &lt;record&gt; &lt;xsl:attribute name="Colour"&gt; &lt;xsl:value-of select="entrydata[@name='Colour']"/&gt; &lt;/xsl:attribute&gt; &lt;/record&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>This produces the following output:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;records&gt; &lt;record Colour="Red"/&gt; &lt;record Colour="YellowBlue"/&gt; &lt;/records&gt; </code></pre> <p>How would I modify the XSLT file so that the output becomes (note the comma separation of <code>&lt;textlist&gt;</code>):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;records&gt; &lt;record Colour="Red"/&gt; &lt;record Colour="Yellow, Blue"/&gt; &lt;/records&gt; </code></pre>
 

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