<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />

<!--  Change parameters here  -->
<xsl:variable name="tn">13</xsl:variable>
<!--                          -->

<!-- Add a packing-slip attachment to the XML -->

<xsl:template match="/">
  <xsl:element name="POlist">
  <xsl:apply-templates select = "//POlist/PO" />
  </xsl:element>
</xsl:template>

<xsl:template match="PO">
  <xsl:choose>
    <xsl:when test = "not (Id/trackNbr = $tn)" >
       <xsl:copy-of select = "." />
    </xsl:when>
    <xsl:otherwise>

      <PO>
      <xsl:choose>
        <xsl:when test = "not(./Attachments)" >
          <xsl:for-each select = "./*" >
            <xsl:copy-of select = "." />
          </xsl:for-each>
          <Attachments>
            <attachment type = "packing-slip">
              <link>http://www.washington.edu</link>
            </attachment>
          </Attachments>
        </xsl:when>
  
        <xsl:otherwise>
          <xsl:if test = "not(name(.) ='Attachments')" >
            <xsl:copy-of select = "." />
          </xsl:if>
 
          <xsl:if test = "name(.) = 'Attachments'" >
            <Attachments>
            <xsl:for-each select = "./*" >
               <xsl:copy-of select = "." />
            </xsl:for-each> 
              <attachment type = "packing-slip">
                <link>http://www.washington.edu</link>
              </attachment>
            </Attachments>
          </xsl:if>
 
       </xsl:otherwise>

      </xsl:choose>
      </PO> 

    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
