title: Retrieving hashmap values in XSLT
body: <p>I am executing an XSLT transformation using java program. Given below is the block of code that is used for transformation.
  Here I am creating a hashmap and setting a value which needs to be accessed in the XSLT.</p>
  
  <pre><code>    TransformerFactory factory = TransformerFactory.newInstance();
      StreamSource xslStream = new StreamSource(inputXSL);
      Transformer transformer = factory.newTransformer(xslStream);
      Map&lt;String,String&gt; mapData = new HashMap&lt;String,String&gt;();
      mapData.put("103", "188 E 6th Street");
      transformer.setParameter("mapData", mapData);
  </code></pre>
  
  <p>The xslt code(inputXSL) that does the transformation is shown below.</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:map="xalan://java.util.Map"
      extension-element-prefixes="map"&gt;
  
  &lt;xsl:param name="mapData"/&gt;
  
  &lt;xsl:template match="/class"&gt;
  
          &lt;html&gt;
              &lt;body&gt;
                  &lt;h3&gt;Student Details&lt;/h3&gt;
                  &lt;table border="1"&gt;
                      &lt;tr bgcolor="#E6E6FA"&gt;
                          &lt;th&gt;Roll Number&lt;/th&gt;
                          &lt;th&gt;First Name&lt;/th&gt;
                          &lt;th&gt;Last Name&lt;/th&gt;
                          &lt;th&gt;Nick Name&lt;/th&gt;
                          &lt;th&gt;Marks&lt;/th&gt;
                          &lt;th&gt;Address&lt;/th&gt;
                      &lt;/tr&gt;
  
  
                      &lt;xsl:for-each select="student"&gt;
                          &lt;tr&gt;
                              &lt;xsl:variable name="rollNumber" select="./@rollno"/&gt;
                              &lt;xsl:variable name="addressData" select="map:get($mapData,$rollNumber)"/&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="./@rollno" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="firstname" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="lastname" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="nickname" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="marks" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;xsl:value-of select="$addressData" /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/xsl:for-each&gt;
                  &lt;/table&gt;
              &lt;/body&gt;
          &lt;/html&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>In the above xslt program I am able get a value for variable addressData if I pass a hard coded key such as '101'(refer the students.xml). But if I iterate over the array and then pass the rollnumber as the key the value in addressData variable is empty. </p>
  
  <p>I am not sure why would the map.:get method would accept a hard coded value but not a parameter. Probably I am missing something.</p>
  
  <p>Given below is the data xml that is passed to the xslt.</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="ParseResponse.xsl"?&gt;
  &lt;class&gt;
      &lt;student rollno="101"&gt;
          &lt;firstname&gt;PPP&lt;/firstname&gt;
          &lt;lastname&gt;LLL&lt;/lastname&gt;
          &lt;nickname&gt;JJJ&lt;/nickname&gt;
          &lt;marks&gt;85&lt;/marks&gt;
      &lt;/student&gt;
      &lt;student rollno="102"&gt;
          &lt;firstname&gt;AAA&lt;/firstname&gt;
          &lt;lastname&gt;CCC&lt;/lastname&gt;
          &lt;nickname&gt;DDD&lt;/nickname&gt;
          &lt;marks&gt;95&lt;/marks&gt;
      &lt;/student&gt;
      &lt;student rollno="103"&gt;
          &lt;firstname&gt;KKK&lt;/firstname&gt;
          &lt;lastname&gt;LLL&lt;/lastname&gt;
          &lt;nickname&gt;WWW&lt;/nickname&gt;
          &lt;marks&gt;90&lt;/marks&gt;
      &lt;/student&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>Can anybody explain why would the map:get method would take hard coded input but not a variable ?</p>