Q:

Multiple transformations to an xml file using xslt 1

Newbie to this site and using xslt but running into a roadblock transforming a SSRS 2008v2 rendered xml file into another XSL raw format for a 3rd Party EDI transfer.   I've been searching this site and others for a while now, but struggling putting it all together. I'm starting with the following raw xml data;
<Invoices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://www.spscommerce.com/RSX"  xsi:schemaLocation="http://www.spscommerce.com/RSX http://tfl- sql01/ReportServer_SQL2012? % 2FTesting%2FINTest&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID= jn5ugdirg4m02nmodnm0hynq&rc%3ASchema=True" Name="INTest">
<Invoices1>  ***need to remove***
  <ivhID_Collection>   ***need to remove***
  <Invoices>...</Invoices>
  <Invoices>...</Invoices>
    <Invoices>
      <Invoice>
        <Header1>
          <InvoiceHeader>...</InvoiceHeader>
          <PaymentTerms>...</PaymentTerms>
          <Dates>...</Dates>
          <Address>...</Address>
          <References>...</References>
          <ChargesAllowances>...</ChargesAllowances>
          <LineItem_Collection>   ***need to remove and replace with </Header>***
            <LineItem>
              <InvoiceLine>...</InvoiceLine>
              <ProductOrItemDescription>...</ProductOrItemDescription>
            </LineItem>
            <LineItem>
              <InvoiceLine>...</InvoiceLine>
              <ProductOrItemDescription>...</ProductOrItemDescription>
            </LineItem>
          </LineItem_Collection>   ***need to remove***
          <Summary>...</Summary>
        </Header1>   ***need to remove***
      </Invoice>
    </Invoices>
    <Invoices>...</Invoices>
    <Invoices>...</Invoices>
    <Invoices>...</Invoices>
  /ivhID_Collection>   ***need to remove***
 </Invoices1>   ***need to remove***
</Invoices>

Trying to get it in this structure instead;
<Invoices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.spscommerce.com/RSX" xsi:schemaLocation="http://www.spscommerce.com/RSX http://tfl-sql01/ReportServer_SQL2012?%2FTesting%2FINDoItBest%20v7&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID=jn5ugdirg4m02nmodnm0hynq&rc%3ASchema=True" Name="INDoItBest v7">
<Invoices>...</Invoices>
<Invoices>...</Invoices>
  <Invoices>
    <Invoice>
      <Header>
        <InvoiceHeader>...</InvoiceHeader>
        <PaymentTerms>...</PaymentTerms>
        <Dates>...</Dates>
        <Address>...</Address>
        <References>...</References>
        <ChargesAllowances>...</ChargesAllowances>
      </Header>
      <LineItem>
        <InvoiceLine>...</InvoiceLine>
        <ProductOrItemDescription>...</ProductOrItemDescription>
      </LineItem>
      <LineItem>
        <InvoiceLine>...</InvoiceLine>
        <ProductOrItemDescription>...</ProductOrItemDescription>
      </LineItem>
      <Summary>...</Summary>
    </Invoice>
  </Invoices>
  <Invoices>...</Invoices>
  <Invoices>...</Invoices>
  <Invoices>...</Invoices>
</Invoices>

I made some progress using this style sheet, but am stuck on the regrouping of the Header tag and the display of the element namespace.   
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:t="http://www.spscommerce.com/RSX"
  exclude-result-prefixes="t">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<! --rule to suppress the undesired nodes-->
<xsl:template match="t:Invoices1|t:ivhID_Collection">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="t:LineItem_Collection">
  <xsl:apply-templates/>
</xsl:template>

<! --<xsl:template match="t:Invoice/t:Header1">
  <xsl:apply-templates/>
</xsl:template>-->

<!--  Identity Transform --> 
<xsl:template match="t:Header1">
  <xsl:copy>
    <xsl:element name="Header">
      <xsl:apply-templates   select="@*|t:InvoiceHeader|t:PaymentTerms|t:Dates|t:Address|t:References|t:ChargesAllowances"/>
    </xsl:element>
    <xsl:apply-templates select="@*|t:LineItem_Collection|t:Summary"/>
  </xsl:copy>
</xsl:template>

<!--  Had to comment out --> 
<! --<xsl:template match="t:Invoice/t:Header1">
  <xsl:apply-templates/>
</xsl:template>-->

The stylesheet produced most of what I needed, but failed when I tried to remove the Header1 tag (code commented out).   Also, struggling to understand why "exclude-result-prefixes" isn't working to remove the namespace from the new xml file. 
<Invoices xmlns="http://www.spscommerce.com/RSX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.spscommerce.com/RSX http://tfl-sql01/ReportServer_SQL2012?%2FTesting%2FINDoItBest%20v7&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID=jn5ugdirg4m02nmodnm0hynq&rc%3ASchema=True" Name="INDoItBest v7">
<Invoices>...</Invoices>
<Invoices>...</Invoices>
<Invoices>
  <Invoice>
    <Header1>
      <Header xmlns="">
        <InvoiceHeader xmlns="http://www.spscommerce.com/RSX">...   </InvoiceHeader>
        <PaymentTerms xmlns="http://www.spscommerce.com/RSX">...   </PaymentTerms>
        <Dates xmlns="http://www.spscommerce.com/RSX">...</Dates>
        <Address xmlns="http://www.spscommerce.com/RSX">...</Address>
        <References xmlns="http://www.spscommerce.com/RSX">...</References>
        <ChargesAllowances xmlns="http://www.spscommerce.com/RSX">...  </ChargesAllowances>
      </Header>
      <LineItem>
        <InvoiceLine>...</InvoiceLine>
        <ProductOrItemDescription>...</ProductOrItemDescription>
      </LineItem>
      <LineItem>
        <InvoiceLine>...</InvoiceLine>
        <ProductOrItemDescription>...</ProductOrItemDescription>
      </LineItem>
      <Summary>
        <TotalAmount>756.8400</TotalAmount>
        <TotalSalesAmount>727.1600</TotalSalesAmount>
        <TotalLineItemNumber>2</TotalLineItemNumber>
      </Summary>
    </Header1>
  </Invoice>
</Invoices>
<Invoices>...</Invoices>
<Invoices>...</Invoices>
<Invoices>...</Invoices>
</Invoices>

Any advice or other options would be greatly appreciated! 

A:

You've already got a template matching t:Header1 in your XSLT, so you shouldn't add another one matching it, as only one can apply. ( In your case, if you did add a template matching t:Invoice\t:Header1 then because of the parent being specified, it would have a higher priority as the one just matching t:Header1 and be used instead). 
What you will need to do, is put all the logic in the single template.  In this case, all you need to do is remove the xsl:copy from that template to avoid the Header1 being copied to the output tree.  Additionally, when you create Header, you are creating it in no namespace, not in the namespace bound to the prefix "t".  Therefore, the child elements will be given new namespace declarations because they will still be in that namespace. 
One way to do it is simply add a "namespace" attribute to the xsl:element, like so:
<xsl:element name="Header" namespace="http://www.spscommerce.com/RSX">

Alternatively, you can create the element by just doing <Header> but you will need to add a default namespace declaration to the XSLT too, to ensure it gets output in the correct namespace. 
Try this XSLT:
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:t="http://www.spscommerce.com/RSX"
  xmlns="http://www.spscommerce.com/RSX"
  exclude-result-prefixes="t">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<! --rule to suppress the undesired nodes-->
<xsl:template match="t:Invoices1|t:ivhID_Collection">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="t:LineItem_Collection">
  <xsl:apply-templates/>
</xsl:template>

<!--  Identity Transform --> 
<xsl:template match="t:Header1">
    <xsl:apply-templates select="@*" />
    <Header>
      <xsl:apply-templates select="@*|t:InvoiceHeader|t:PaymentTerms|t:Dates|t:Address|t:References|t:ChargesAllowances"/>
    </Header>
    <xsl:apply-templates select="t:LineItem_Collection|t:Summary"/>
</xsl:template>
</xsl:stylesheet>

As a side note, in your XSLT you were also doing this immediately after creating the Header element
<xsl:apply-templates select="@*|t:LineItem_Collection|t:Summary"/>

This would fail if the Header1 had attributes you wanted to copy, as it is an error to try to add attributes to a parent element after you have created child elements.  This is why in my XSLT I have split the statement into two.