Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with XSL sorting
    text
    copied!<p>I am having a problem trying to sort with an XSL file using the XslCompiledTransform in CLR4.0. Here is my sample XML file (Note: there is a space after the second <code>&lt;foo&gt;</code> element):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;reflection&gt; &lt;apis&gt; &lt;api id="A"&gt; &lt;foos&gt; &lt;foo/&gt; &lt;/foos&gt; &lt;/api&gt; &lt;api id="B"&gt; &lt;foos&gt; &lt;foo/&gt; &lt;/foos&gt; &lt;/api&gt; &lt;/apis&gt; &lt;/reflection&gt; </code></pre> <p>When I apply the following XSL file:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;table&gt; &lt;xsl:apply-templates select="/reflection/apis/api"&gt; &lt;xsl:sort select="@id" /&gt; &lt;/xsl:apply-templates&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="api"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:value-of select="@id" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I get the following result:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;B&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;A&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>However, if I remove the space after the second <code>&lt;foo&gt;</code> element, the resulting file is sorted correctly. This seems like it's probably a bug in the XslCompiledTransform, but I was hoping someone might have a workaround.</p> <p>Edit: If anyone is having trouble reproducing it, here is the code I am using:</p> <pre><code>XslCompiledTransform xslt = new XslCompiledTransform(); XsltSettings transformSettings = new XsltSettings(true, true); xslt.Load("CreateVSToc.xsl", transformSettings, new XmlUrlResolver()); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreWhitespace = true; Stream readStream = File.Open("reflection.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); using (XmlReader reader = XmlReader.Create(readStream, readerSettings)) { Stream outputStream = File.Open("toc.xml", FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete); using (XmlWriter writer = XmlWriter.Create(outputStream, xslt.OutputSettings)) { XsltArgumentList arguments = new XsltArgumentList(); xslt.Transform(reader, arguments, writer); } } </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