Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To do this using only <strong>one</strong> transform process would require your newly created show elements to be seen as a <strong>node-set</strong> so the templates can use the internal <strong>xsl:sort</strong> mechanics. The <a href="http://www.w3.org/TR/xslt" rel="nofollow noreferrer">XSL Transformations (XSLT) Version 1.0 spec</a> does not have a method to turn self created elements into a node set. However, the <a href="http://msdn.microsoft.com/en-us/library/hz88kef0(VS.71).aspx" rel="nofollow noreferrer">MSXML parser</a> (3.0 or greater) does have an extension to provide that functionality. Also, there's an <a href="http://www.exslt.org/exsl/functions/node-set/index.html" rel="nofollow noreferrer">exslt extension</a> that I think some newer versions of Firefox support that will allow this dynamic swap of a variable to a node-set. But anyways, here's a stylesheet that works properly using the MSXML parser.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="shows"&gt; &lt;xsl:apply-templates select="//data[@alias='Dates']"/&gt; &lt;/xsl:variable&gt; &lt;shows&gt; &lt;xsl:apply-templates select="msxsl:node-set($shows)//show"&gt; &lt;xsl:sort select="substring(date, 7, 4)"/&gt;&lt;!-- year --&gt; &lt;xsl:sort select="substring(date, 4, 2)"/&gt;&lt;!-- month --&gt; &lt;xsl:sort select="substring(date, 1, 2)"/&gt;&lt;!-- day --&gt; &lt;/xsl:apply-templates&gt; &lt;/shows&gt; &lt;/xsl:template&gt; &lt;xsl:template match="show"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="data[@alias='Dates']"&gt; &lt;xsl:call-template name="eachDate"&gt; &lt;xsl:with-param name="node" select=".."/&gt; &lt;xsl:with-param name="dates" select="."/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="eachDate"&gt; &lt;xsl:param name="node" select="."/&gt; &lt;xsl:param name="dates" select="''"/&gt; &lt;xsl:if test="string-length($dates)"&gt; &lt;show&gt; &lt;name&gt;&lt;xsl:value-of select="$node/data[@alias='Show']/text()"/&gt;&lt;/name&gt; &lt;date&gt;&lt;xsl:value-of select="substring-before($dates, ',')"/&gt;&lt;/date&gt; &lt;/show&gt; &lt;xsl:call-template name="eachDate"&gt; &lt;xsl:with-param name="node" select="$node"/&gt; &lt;xsl:with-param name="dates" select="substring-after($dates, ',')"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&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