Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Do I have a problem with my key definition or the way that I am trying to use it?</p> </blockquote> <p>There is no problem with any of them:</p> <p><strong>I cannot reproduce the reported output</strong>. This means that if there really is any problem, it is in the code not shown to us.</p> <p><strong>The provided transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables" &gt; &lt;xsl:key name="preferences" match="preferences/preference" use="@code"/&gt; &lt;xsl:template match="Reservation/Detail" &gt; &lt;xsl:for-each select="Preferences/Preference"&gt; &lt;xsl:if test ="string-length(./PreferenceCode)&gt;0"&gt; &amp;#160;&amp;#160;&amp;#160;&amp;#160;* ( &lt;xsl:value-of select="./PreferenceCode"/&gt;) &lt;xsl:choose&gt; &lt;xsl:when test="./PreferenceCode!='PETS'"&gt; &lt;xsl:call-template name="prefmap"&gt; &lt;xsl:with-param name="code" select="./PreferenceCode"/&gt; &lt;/xsl:call-template&gt; &lt;br/&gt; &lt;br/&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;xsl:template name="prefmap"&gt; &lt;xsl:param name="code"/&gt; You got here (called template) with code &lt;xsl:value-of select="$code"/&gt; &lt;xsl:for-each select="document('')"&gt; &lt;xsl:value-of select="key('preferences',$code)"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;m:Maps xmlns=""&gt; &lt;preferences&gt; &lt;preference code="ANT"&gt; Hypoallergenic Bedding &lt;/preference&gt; &lt;preference code="NSK"&gt; Non-smoking Room &lt;/preference&gt; &lt;preference code="SMK"&gt; Smoking Room &lt;/preference&gt; &lt;/preferences&gt; &lt;/m:Maps&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the following XML document</strong> (no XML document was provided in the question!):</p> <pre><code>&lt;Reservation&gt; &lt;Detail&gt; &lt;Preferences&gt; &lt;Preference&gt; &lt;PreferenceCode&gt;ANT&lt;/PreferenceCode&gt; &lt;/Preference&gt; &lt;Preference&gt; &lt;PreferenceCode&gt;NSK&lt;/PreferenceCode&gt; &lt;/Preference&gt; &lt;Preference&gt; &lt;PreferenceCode&gt;SMK&lt;/PreferenceCode&gt; &lt;/Preference&gt; &lt;Preference&gt; &lt;PreferenceCode&gt;PETS&lt;/PreferenceCode&gt; &lt;/Preference&gt; &lt;/Preferences&gt; &lt;/Detail&gt; &lt;/Reservation&gt; </code></pre> <p><strong>produces exactly the expected result</strong>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; * ( ANT) You got here (called template) with code ANT Hypoallergenic Bedding &lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt;&lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt; * ( NSK) You got here (called template) with code NSK Non-smoking Room &lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt;&lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt; * ( SMK) You got here (called template) with code SMK Smoking Room &lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt;&lt;br xmlns="http://www.w3.org/1999/xhtml" xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:m="http://mapping.tables"/&gt; * ( PETS) </code></pre> <p><strong>Do Note:</strong></p> <p>All the following 7 XSLT processors produce exactly the same (above) result: MSXML3/4, XslCompiledTransform, XslTransform, Saxon 6.5.4, Saxon 9.1.05, AltovaXML (XmlSPY).</p>
 

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