title: XSLT: Fill table based on common attribute value under different elements
body: <p>I've been trying to create a table with XSLT based on identical attribute values in XML file. I'm struggling with linking the elements based on identical attributes and looping through the XML file retrieving the necessary data.</p>
  
  <p>The XML file i have:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;LandXML&gt;
    &lt;Survey&gt;
      &lt;GPSSetup id="Setup1" stationName="Ref1"&gt;
      &lt;/GPSSetup&gt;
      &lt;GPSSetup id="Setup2" stationName="Ref2"&gt;
      &lt;/GPSSetup&gt;
      &lt;GPSSetup id="Setup3" stationName="Ref3"&gt;
      &lt;/GPSSetup&gt;
      ...
    &lt;/Survey&gt;
    &lt;Survey&gt;
      &lt;GPSSetup id="id1" name="0001"&gt;
      &lt;/GPSSetup&gt;
      &lt;GPSSetup id="id2" name="0002"&gt;
      &lt;/GPSSetup&gt;
      &lt;GPSSetup id="id3" name="0003"&gt;
      &lt;/GPSSetup&gt;
      ...
      &lt;GPSVector setupID_a="Ref1"&gt;
        &lt;TargetPoint pntRef="0001"&gt;&lt;/TargetPoint&gt;
      &lt;/GPSVector&gt;
      &lt;GPSVector setupID_a="Ref1"&gt;
        &lt;TargetPoint pntRef="0002"&gt;&lt;/TargetPoint&gt;
      &lt;/GPSVector&gt;
      &lt;GPSVector setupID_a="Ref2"&gt;
        &lt;TargetPoint pntRef="0003"&gt;&lt;/TargetPoint&gt;
      &lt;/GPSVector&gt;
      ...
    &lt;/Survey&gt;
    &lt;HexagonLandXML&gt;
      &lt;Point uniqueID="0001"&gt;
        &lt;Coordinates n="1234"&gt;&lt;/Coordinates&gt;
      &lt;/Point&gt;
      &lt;Point uniqueID="name2"&gt;
        &lt;Coordinates n="1225"&gt;&lt;/Coordinates&gt;
      &lt;/Point&gt;
      &lt;Point uniqueID="name3"&gt;
        &lt;Coordinates n="1335"&gt;&lt;/Coordinates&gt;
      &lt;/Point&gt;
    &lt;/HexagonLandXML&gt;
  &lt;/LandXML&gt;
  </code></pre>
  
  <p>I want to output a html file where under every "stationName" value that is found in the XML, a table is created where the corresponding "pntRef" and "n" values are shown.</p>
  
  <p>The output i would like to achieve:</p>
  
  <pre><code>Ref1:
  0001   1234
  0002   1225
  
  Ref2:
  0003   1335
  </code></pre>
  
  <p>The XSLT file i have made so far:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
              xmlns:l="http://www.landxml.org/schema/LandXML-1.2"
              xmlns:h="http://xml.hexagon.com/schema/HeXML-1.7"
              xmlns:msxsl="urn:schemas-microsoft-com:xslt"
              exclude-result-prefixes="h l"
              extension-element-prefixes="h l msxsl"&gt;
  &lt;xsl:output method="html" indent="no" encoding="utf-8"/&gt; 
  &lt;xsl:variable name="fileExt" select="'html'"/&gt;
  
  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;style&gt;
        &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;xsl:apply-templates select="//l:LandXML/l:Survey[1]/l:GPSSetup"&gt;
        &lt;/xsl:apply-templates&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:key name="keyLGPSVector" match="l:GPSVector" use="@setupID_A"/&gt;
  &lt;xsl:key name="keyH" match="h:Point" use="@uniqueID"/&gt;
  
  &lt;xsl:template match="//l:LandXML/l:Survey[1]/l:GPSSetup"&gt;
    &lt;xsl:variable name="Survey1L" select="."/&gt;
    &lt;xsl:variable name="Survey1LID" select="key('keyLGPSVector', $Survey1L/@id)"/&gt;
    &lt;xsl:variable name="PointH" select="key('keyH', $Survey1L/@id)"/&gt;
  
    &lt;xsl:for-each select="."&gt;
      &lt;h5&gt;
      &lt;xsl:value-of select="@stationName"/&gt;
      &lt;/h5&gt;
  
      &lt;table&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Number&lt;/th&gt;
                  &lt;th&gt;n [m]&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;xsl:for-each select="$Survey1LID"&gt;
                  &lt;xsl:if test="$Survey1LID/@setupID_A = $Survey1L/@id"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;xsl:value-of select="current()/l:TargetPoint/@pntRef"/&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;xsl:value-of select="$PointH/h:Coordinates/@n"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:for-each&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>With this i can achieve that the correct "pntRef" values are shown under each "Ref()" heading, but i cannot get the "n" value. From reading this forum i understand that for-each is probably not the best element to be used in this case.</p>
  
  <p>Sorry if the editing is wrong or non-transparent, this is my first post.</p>