<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="./matts.xsl"?>

<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>
<!--                          -->

<!-- Update the status element for a given tracking number -->

<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 = "." />           <!-- copy all PO's with     -->
    </xsl:when>                               <!-- a different tracking # -->
                                              <!-- verbatim               -->
    <xsl:otherwise>
      <PO>
      <xsl:for-each select = "./*" >
        <xsl:if test = "not(name(.) = 'Id')" >
          <xsl:copy-of select = "." />        <!-- copy all non-ID elements -->
        </xsl:if>

        <xsl:if test = "name(.) = 'Id'" >
          <Id>
          <xsl:for-each select = "./*" >
             <xsl:if test = "not(name(.) = 'status')" >
                <xsl:copy-of select = "." />
             </xsl:if>
             <xsl:if test = "name(.) = 'status' " >
                <status>Shipped</status>      <!-- set status = "Shipped"   -->
             </xsl:if>
          </xsl:for-each> 
          </Id>
        </xsl:if>

      </xsl:for-each>
      </PO>
    </xsl:otherwise>

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

</xsl:stylesheet>
