title: Group the Coordinates under each Mappoint
body: <p>I'm trying to use XSLT to process data by grouping it.</p>
  
  <p>Sample XML</p>
  
  <pre><code>  &lt;DELIVERYLEG&gt;
          &lt;DELIVERYINSTRUCTION&gt;
              &lt;MAP_REFERENCE_SYSTEM&gt;EUREF-FIN&lt;/MAP_REFERENCE_SYSTEM&gt;
              &lt;MAP_COORDINATE_TYPE&gt;ETRS-TM35FIN&lt;/MAP_COORDINATE_TYPE&gt;
              &lt;XY_TEXT&gt;XY&lt;/XY_TEXT&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;3&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;695123&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;3&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;UserWay&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;1&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;Turning&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;695123&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT&gt;SALMI AINO&lt;/MAP_POINT_COMMENT&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;4&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951337&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;5&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;1&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951337&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;5&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951271&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;5&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;2&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951271&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;6&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951479&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;6&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;1&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951479&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;7&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951507&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;6&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;2&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951507&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;8&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951598&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;6&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;3&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951598&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
              &lt;maprows&gt;
                  &lt;MAP_POINT_TOTAL_ROWS&gt;18&lt;/MAP_POINT_TOTAL_ROWS&gt;
                  &lt;MAP_POINT_ROW&gt;9&lt;/MAP_POINT_ROW&gt;
                  &lt;MAP_POINT_NAME&gt;6951734&lt;/MAP_POINT_NAME&gt;
                  &lt;MAP_POINT_GROUP&gt;6&lt;/MAP_POINT_GROUP&gt;
                  &lt;MAP_POINT_DISPLAY_TYPE&gt;Line&lt;/MAP_POINT_DISPLAY_TYPE&gt;
                  &lt;COORDINATE_DISPLAY_ORDER&gt;4&lt;/COORDINATE_DISPLAY_ORDER&gt;
                  &lt;MAP_POINT_TYPE&gt;ForestRoad&lt;/MAP_POINT_TYPE&gt;
                  &lt;MAP_POINT_COORDINATES&gt;6951734&lt;/MAP_POINT_COORDINATES&gt;
                  &lt;MAP_POINT_COMMENT /&gt;
              &lt;/maprows&gt;
          &lt;/DELIVERYINSTRUCTION&gt;
      &lt;/DELIVERYLEG&gt;
  </code></pre>
  
  <p>It should group on MAP_POINT_GROUP and all coordinate should come under that group.
  Below is the output excepted....  </p>
  
  <pre><code>&lt;MapPoint MapPointDisplayType="Turning" MapPointType="UserWay"&gt;
      &lt;MapPointName&gt;695123&lt;/MapPointName&gt;
      &lt;MapPointComment&gt;Kom&lt;/MapPointComment&gt;
      &lt;MapCoordinates&gt;
          &lt;Coordinates Order="1" Type="XY"&gt;695123&lt;/Coordinates&gt;
      &lt;/MapCoordinates&gt;                          
  &lt;/MapPoint&gt; 
  &lt;MapPoint MapPointDisplayType="Line" MapPointType="ForestRoad"&gt;
      &lt;MapPointName&gt;6951271&lt;/MapPointName&gt;
      &lt;MapCoordinates&gt;
          &lt;Coordinates Order="1" Type="XY"&gt;6951337&lt;/Coordinates&gt;
          &lt;Coordinates Order="2" Type="XY"&gt;6951271&lt;/Coordinates&gt;
      &lt;/MapCoordinates&gt;                          
  &lt;/MapPoint&gt; 
  &lt;MapPoint MapPointDisplayType="Line" MapPointType="ForestRoad"&gt;
      &lt;MapPointName&gt;6951479&lt;/MapPointName&gt;
      &lt;MapCoordinates&gt;
          &lt;Coordinates Order="1" Type="XY"&gt;6951479&lt;/Coordinates&gt;
          &lt;Coordinates Order="2" Type="XY"&gt;6951507&lt;/Coordinates&gt;
          &lt;Coordinates Order="3" Type="XY"&gt;6951598&lt;/Coordinates&gt;
          &lt;Coordinates Order="4" Type="XY"&gt;6951734&lt;/Coordinates&gt;
      &lt;/MapCoordinates&gt;                          
  &lt;/MapPoint&gt;
  </code></pre>
  
  <p>How would I deal with this?</p>
  
  <p>Below is existing XSLT </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0" xmlns:ns0="http://schemas.microsoft.com/BizTalk/2003"
                  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                  xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
                  exclude-result-prefixes="msxsl"
                  xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp"
                  xmlns:ReformatDate="http://functions/xslt"&gt;
  
      &lt;xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/&gt;
  
      &lt;xsl:template match="/"&gt;
          &lt;xsl:apply-templates select="/DeliveryLeg" /&gt;
          &lt;!--&lt;xsl:apply-templates select="/DeliveryLeg" /&gt;--&gt;
  
      &lt;/xsl:template&gt;
  
  
  
      &lt;xsl:template match="/DeliveryLeg"&gt;
          &lt;DeliveryInstruction&gt;
              &lt;SupplyPoint&gt;
                  &lt;xsl:attribute name="LocationType"&gt;
                      &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/ORIGIN_VALUE/text()"/&gt;
                  &lt;/xsl:attribute&gt;
                  &lt;SupplyPointCode&gt;
                      &lt;xsl:attribute name="Agency"&gt;
                          &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/SUPPLY_POINT_CODE/text()"/&gt;
                      &lt;/xsl:attribute&gt;
                      &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/ERA_NRO/text()"/&gt;
                  &lt;/SupplyPointCode&gt;
                  &lt;SupplyPointCode&gt;
                      &lt;xsl:attribute name="Agency"&gt;
                          &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/LOGISTICS_BUYER/text()"/&gt;
                      &lt;/xsl:attribute&gt;
                      &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/ERA_NRO/text()"/&gt;
                  &lt;/SupplyPointCode&gt;
                  &lt;SupplyPointDescription&gt;
                      &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/ROADSIDE_STOCK/text()"/&gt;
                  &lt;/SupplyPointDescription&gt;
                  &lt;MapCoordinates&gt;
                      &lt;xsl:attribute name="MapReferenceSystem"&gt;
                          &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/MAP_REFERENCE_SYSTEM/text()"/&gt;
                      &lt;/xsl:attribute&gt;
                      &lt;xsl:attribute name="MapCoordinateType"&gt;
                          &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/MAP_COORDINATE_TYPE/text()"/&gt;
                      &lt;/xsl:attribute&gt;
                      &lt;Coordinates&gt;
                          &lt;xsl:attribute name="CoordinateFormatType"&gt;
                              &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/XY_TEXT/text()"/&gt;
                          &lt;/xsl:attribute&gt;
                          &lt;xsl:value-of select ="logforce..LF_HEADER_LAHTOVARASTO/logforce..LF_LAHTOVARASTO/ERA_KOORDINAATIT/text()"/&gt;
                      &lt;/Coordinates&gt;
                  &lt;/MapCoordinates&gt;
                  &lt;!--New Logic for MapPoint--&gt;
                  &lt;SupplyPointCharacteristics&gt;
  
                      &lt;NEW CODE SHOULD BE THERE&gt;
  
  
                  &lt;/SupplyPointCharacteristics&gt;
              &lt;/SupplyPoint&gt;
          &lt;/DeliveryInstruction&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>