title: How to flatten hierarchical XML file using XSLT stylesheet with namespace in XML file
body: <p>I'm struggling with XSLT and XML...quite new in this arena.</p>
  
  <p>I have a multi-level (hierarchical) XML file that I need to flatten. I've build my very first XSLT file and it worked with a XML file I had created for development. However, it keeps failing when I'm pointing it to the intended XML file. I've found that it works if I delete the namespace from the XML file. I've also tried to prefix the namespace in the XSLT file but couldn't get that to work either.</p>
  
  <p>After hours of searching the internet, and trying all kinds of fixes...I finally have to pull over and ask for directions. </p>
  
  <p>I've added a small snippet of the XSLT file where I try to select "LoadID" and also the XML file below. </p>
  
  <p>XSLT:</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="http://www.leanlogistics.com/DESchema/load"&gt;
  &lt;xsl:output method="xml" indent="yes" version="2.0" encoding="UTF-8"/&gt;
  &lt;xsl:template match="/"&gt;
      &lt;xsl:element name="LoadExtractRecords"&gt;
          &lt;xsl:for-each select="LoadExtractRecords/LoadExtractRecord"&gt;
              &lt;xsl:element name="LoadExtractRecord"&gt;
                  &lt;xsl:element name="LoadID"&gt;
                      &lt;xsl:value-of select="LoadID"/&gt;
                  &lt;/xsl:element&gt;
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>XML File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;LoadExtractRecords xmlns="http://www.leanlogistics.com/DESchema/load"&gt;
    &lt;LoadExtractRecord&gt;
      &lt;LoadID&gt;41955711&lt;/LoadID&gt;
      &lt;Company id="14188"&gt;COMPANY NAME&lt;/Company&gt;
      &lt;ShipperLoadRef&gt;41955711&lt;/ShipperLoadRef&gt;
      &lt;Status id="1071"&gt;COMPLETED&lt;/Status&gt;
      &lt;Type id="1525"&gt;LOAD&lt;/Type&gt;
      &lt;LoadGroup id="63617"&gt;RESTOCK&lt;/LoadGroup&gt;
      &lt;Contact id="86226"&gt;
          &lt;FirstName&gt;Jennifer&lt;/FirstName&gt;
          &lt;LastName&gt;Benson&lt;/LastName&gt;
          &lt;UserName&gt;jenniferbenson&lt;/UserName&gt;
      &lt;/Contact&gt;
      &lt;CreateDate&gt;2011-08-28T20:56:19-04:00&lt;/CreateDate&gt;
    &lt;/LoadExtractRecord&gt;
  &lt;/LoadExtractRecords&gt;
  </code></pre>
  
  <p>The XSLT above produces the following result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LoadExtractRecords xmlns="http://www.leanlogistics.com/DESchema/load" /&gt;
  </code></pre>
  
  <p>When I delete the namespace in the XML file, I get the intended result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LoadExtractRecords xmlns="http://www.leanlogistics.com/DESchema/load"&gt;
    &lt;LoadExtractRecord&gt;
      &lt;LoadID&gt;41955711&lt;/LoadID&gt;
    &lt;/LoadExtractRecord&gt;
  &lt;/LoadExtractRecords&gt;
  </code></pre>
  
  <p>I would greatly appreciate any help.
  Thanks</p>