Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL associative sorting using a field substring
    primarykey
    data
    text
    <p>The transformation I am writing must compose a comma separated string value from a given node set. The resulting string must be sorted according to a random (non-alphabetic) mapping for the first character in the input values.</p> <p>I came up with this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tmp="http://tempuri.org" exclude-result-prefixes="tmp" &gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;tmp:sorting-criterion&gt; &lt;code value="A"&gt;5&lt;/code&gt; &lt;code value="B"&gt;1&lt;/code&gt; &lt;code value="C"&gt;3&lt;/code&gt; &lt;/tmp:sorting-criterion&gt; &lt;xsl:template match="/InputValueParentNode"&gt; &lt;xsl:element name="OutputValues"&gt; &lt;xsl:for-each select="InputValue"&gt; &lt;xsl:sort select="document('')/*/tmp:sorting-criterion/code[@value=substring(.,1,1)]" data-type="number"/&gt; &lt;xsl:value-of select="normalize-space(.)"/&gt; &lt;xsl:if test="position() != last()"&gt; &lt;xsl:text&gt;,&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It doesn't work and looks like the XPath <code>document('')/*/tmp:sorting-criterion/code[@value=substring(.,1,1)]</code> does not evaluate as I expect. I've checked to substitute the <code>substring(.,1,1)</code> for a literal and it evaluates to the proper value.</p> <p>So, am I missing something that makes the sorting XPath expression not to evaluate as I expect or is it simply impossile to do it this way?</p> <p>If not possible to create a XPath expression that works, is there a work around to achieve my purpose?</p> <p><strong>Note:</strong> I'm constrained to XSLT-1.0</p> <p><strong>Sample Input:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;InputValueParentNode&gt; &lt;InputValue&gt;A input value&lt;/InputValue&gt; &lt;InputValue&gt;B input value&lt;/InputValue&gt; &lt;InputValue&gt;C input value&lt;/InputValue&gt; &lt;/InputValueParentNode&gt; </code></pre> <p><strong>Expected ouput:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;OutputValues&gt;B input value,C input value,A input value&lt;/OutputValues&gt; </code></pre>
    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.
 

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