title: XSL for each for different nodes in XML file
body: <p>This is my XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet  type="text/xsl" href="coursestyle.xsl"?&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;s:Body&gt;
        &lt;ns0:FindCoursesForOffenderResponse xmlns:ns0="http://H.FindCoursesForOffenderResponse"&gt;
           &lt;ns0:SiteList&gt;
              &lt;ns0:SiteEntity&gt;
                 &lt;ns0:SiteId&gt;10&lt;/ns0:SiteId&gt;
                 &lt;ns0:SiteName&gt;Ramada Watford&lt;/ns0:SiteName&gt;
              &lt;/ns0:SiteEntity&gt;
              &lt;ns0:SiteEntity&gt;
                 &lt;ns0:SiteId&gt;20&lt;/ns0:SiteId&gt;
                 &lt;ns0:SiteName&gt;Ramada Jarvis (Comet) Hotel&lt;/ns0:SiteName&gt;
              &lt;/ns0:SiteEntity&gt;
           &lt;/ns0:SiteList&gt;
           &lt;ns0:CourseList&gt;
              &lt;ns0:CourseEntity&gt;
                 &lt;ns0:CourseId&gt;50&lt;/ns0:CourseId&gt;
                 &lt;ns0:SiteId&gt;10&lt;/ns0:SiteId&gt;
              &lt;/ns0:CourseEntity&gt;
              &lt;ns0:CourseEntity&gt;
                 &lt;ns0:CourseId&gt;10&lt;/ns0:CourseId&gt;
                 &lt;ns0:SiteId&gt;10&lt;/ns0:SiteId&gt;
              &lt;/ns0:CourseEntity&gt;
              &lt;ns0:CourseEntity&gt;
                 &lt;ns0:CourseId&gt;20&lt;/ns0:CourseId&gt;
                 &lt;ns0:SiteId&gt;20&lt;/ns0:SiteId&gt;
              &lt;/ns0:CourseEntity&gt;
           &lt;/ns0:CourseList&gt;
        &lt;/ns0:FindCoursesForOffenderResponse&gt;
     &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>I want to select the <code>SiteName</code> for each <code>CourseEntity</code>. For example for the <code>CourseID = 50</code> the <code>SiteName</code> should be <code>Ramada Watford</code>.</p>
  
  <p>So far I have this XSL but it doesn't work.</p>
  
  <pre><code>&lt;?xml version='1.0'?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://H.FindCoursesForOffenderResponse" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;xsl:output method="html"/&gt;
  &lt;xsl:param  name="lnum"&gt;123&lt;/xsl:param&gt;
  
  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
    &lt;body&gt;
      &lt;ul&gt;
  
      &lt;xsl:for-each select="s:Envelope/s:Body/ns0:FindCoursesForOffenderResponse/ns0:CourseList/ns0:CourseEntity"&gt;
          &lt;xsl:variable  name="currEntity"&gt;&lt;xsl:value-of select="ns0:SiteId"/&gt;&lt;/xsl:variable&gt;
              &lt;xsl:value-of select="$currEntity"/&gt;&lt;br/&gt;
              &lt;xsl:for-each select="s:Envelope/s:Body/ns0:FindCoursesForOffenderResponse/ns0:SiteList/ns0:SiteEntity[ns0:SiteId=$currEntity]"&gt;            
            &lt;li&gt;
              &lt;xsl:value-of select="ns0:SiteName"/&gt;
  
            &lt;/li&gt;
                &lt;/xsl:for-each&gt;
            &lt;/xsl:for-each&gt;
  
      &lt;/ul&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The first <code>for-each</code> loop runs through <code>CourseEntities</code> and the inner loop is trying to find the relevant site name for each course id. </p>
  
  <p>Any idea?</p>
  
  <p>output </p>
  
  <pre><code>&lt;couseID&gt; - &lt;sitename&gt;
  50 - Ramada Watford
  20 -   Ramada Jarvis (Comet) Hotel
  </code></pre>