Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>I. AN XSLT 1.0 solution using FXSL 1.x</strong></p> <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext" &gt; &lt;xsl:import href="strSplit-to-Words.xsl"/&gt; &lt;xsl:output indent="yes" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="/*"&gt; &lt;xsl:variable name="vDates"&gt; &lt;xsl:for-each select="node"&gt; &lt;nodeData name="{data[@alias = 'Show']}"&gt; &lt;xsl:call-template name="str-split-to-words"&gt; &lt;xsl:with-param name="pStr" select="data[@alias = 'Dates']"/&gt; &lt;xsl:with-param name="pDelimiters" select="','"/&gt; &lt;/xsl:call-template&gt; &lt;/nodeData&gt; &lt;/xsl:for-each&gt; &lt;/xsl:variable&gt; &lt;xsl:apply-templates select="ext:node-set($vDates)/*/*[text()]"&gt; &lt;xsl:sort data-type="number" select="substring(.,7)"/&gt; &lt;xsl:sort data-type="number" select="substring(.,4,2)"/&gt; &lt;xsl:sort data-type="number" select="substring(.,1,2)"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="word"&gt; &lt;show&gt; &lt;name&gt; &lt;xsl:value-of select="../@name"/&gt; &lt;/name&gt; &lt;date&gt; &lt;xsl:value-of select="."/&gt; &lt;/date&gt; &lt;/show&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided "XML document", corrected to be well-formed</strong> (When will you, people, learn to provide a well-formed XML document? Is it <em>that</em> difficult?):</p> <pre><code>&lt;t&gt; &lt;node id="1"&gt; &lt;data alias="Show"&gt;ShowName1&lt;/data&gt; &lt;data alias="Dates"&gt;21/04/2009,23/04/2009,27/04/2009,&lt;/data&gt; &lt;/node&gt; &lt;node id="2"&gt; &lt;data alias="Show"&gt;ShowName2&lt;/data&gt; &lt;data alias="Dates"&gt;22/04/2009,25/04/2009,29/04/2009,&lt;/data&gt; &lt;/node&gt; &lt;/t&gt; </code></pre> <p><strong>produces the wanted result</strong>:</p> <pre><code>&lt;show&gt; &lt;name&gt;ShowName1&lt;/name&gt; &lt;date&gt;21/04/2009&lt;/date&gt; &lt;/show&gt; &lt;show&gt; &lt;name&gt;ShowName2&lt;/name&gt; &lt;date&gt;22/04/2009&lt;/date&gt; &lt;/show&gt; &lt;show&gt; &lt;name&gt;ShowName1&lt;/name&gt; &lt;date&gt;23/04/2009&lt;/date&gt; &lt;/show&gt; &lt;show&gt; &lt;name&gt;ShowName2&lt;/name&gt; &lt;date&gt;25/04/2009&lt;/date&gt; &lt;/show&gt; &lt;show&gt; &lt;name&gt;ShowName1&lt;/name&gt; &lt;date&gt;27/04/2009&lt;/date&gt; &lt;/show&gt; &lt;show&gt; &lt;name&gt;ShowName2&lt;/name&gt; &lt;date&gt;29/04/2009&lt;/date&gt; &lt;/show&gt; </code></pre> <p><strong>II. One possible XSLT 2.0 solution</strong>:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:template match="/*"&gt; &lt;xsl:variable name="vAllData" as="xs:string+"&gt; &lt;xsl:for-each select="node"&gt; &lt;xsl:variable name="vName" select="data[@alias='Show']"/&gt; &lt;xsl:for-each select= "tokenize(data[@alias='Dates'], ',')[.]"&gt; &lt;xsl:value-of select="concat($vName, '+',.)"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; &lt;/xsl:variable&gt; &lt;xsl:for-each select="$vAllData"&gt; &lt;xsl:sort data-type="number" select= "substring(substring-after(.,'+'),7)"/&gt; &lt;xsl:sort data-type="number" select= "substring(substring-after(.,'+'),4,2)"/&gt; &lt;xsl:sort data-type="number" select= "substring(substring-after(.,'+'),1,2)"/&gt; &lt;show&gt; &lt;name&gt; &lt;xsl:value-of select="substring-before(.,'+')"/&gt; &lt;/name&gt; &lt;date&gt; &lt;xsl:value-of select="substring-after(.,'+')"/&gt; &lt;/date&gt; &lt;/show&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When the above XSLT 2.0 transformation is applied on the same document, the same correct result is produced</strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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