title: Add node based on parameter of XML using XSL
body: <p>My objective is to add a new element to the XML file if one of the current child elements is equal to a condition.  If that condition is not met continue to use the current template of the original XML file.  </p>
  
  <p>I have a sample XML file below which currently containts 2 ordered items. The overall structure of the XML file will remain the same but the number of items ordered will be variable which can add additional AlbumOrderItems as customer orders will be unique with each XML file.   </p>
  
  <p>Original XML file</p>
  
  <pre><code>&lt;AlbumOrder&gt; 
     &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt; 
     &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
     &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
     &lt;NumItems&gt;2&lt;/NumItems&gt; 
     &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt; 
  &lt;AlbumOrderItem&gt; 
     &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt;
     &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
     &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
     &lt;PartnerOrderItemID&gt;1&lt;/PartnerOrderItemID&gt; 
     &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt; 
     &lt;ProductCategory&gt;ALBUM&lt;/ProductCategory&gt; 
     &lt;Quantity&gt;2&lt;/Quantity&gt; 
  &lt;ShipAddress&gt; 
     &lt;FirstName&gt;Joe&lt;/FirstName&gt; 
     &lt;LastName&gt;Black&lt;/LastName&gt; 
  &lt;/ShipAddress&gt; 
  &lt;/AlbumOrderItem&gt;
  &lt;AlbumOrderItem&gt; 
      &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt; 
      &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
      &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
      &lt;PartnerOrderItemID&gt;2&lt;/PartnerOrderItemID&gt; 
      &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt;  
      &lt;ProductCategory&gt;CARD&lt;/ProductCategory&gt;  
      &lt;Quantity&gt;1&lt;/Quantity&gt; 
      &lt;Package&gt;10&lt;/Package&gt; 
      &lt;NumPrints&gt;10&lt;/NumPrints&gt; 
  &lt;ShipAddress&gt; 
      &lt;FirstName&gt;Joe&lt;/FirstName&gt;
      &lt;LastName&gt;Black&lt;/LastName&gt; 
  &lt;/ShipAddress&gt; 
  &lt;/AlbumOrderItem&gt; 
  &lt;/AlbumOrder&gt;
  </code></pre>
  
  <p>If the ProductCategory is equal to "ALBUM" then add a new element to AlbumOrderItem.The sample XML output below contains two new added elements titled:
  Package and NumPrints 
  these were both added to the first AblumOrderItem</p>
  
  <p>Desired output XML</p>
  
  <pre><code>&lt;AlbumOrder&gt; 
     &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt; 
     &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
     &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
     &lt;NumItems&gt;2&lt;/NumItems&gt; 
     &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt; 
   &lt;AlbumOrderItem&gt; 
     &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt;
     &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
     &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
     &lt;PartnerOrderItemID&gt;1&lt;/PartnerOrderItemID&gt; 
     &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt; 
     &lt;ProductCategory&gt;ALBUM&lt;/ProductCategory&gt; 
     &lt;Quantity&gt;2&lt;/Quantity&gt; 
     &lt;Package&gt;XY&lt;/Package&gt;      ****NODE to add
     &lt;NumPrints&gt;Z&lt;/NumPrints&gt;   ****NODE to add
  &lt;ShipAddress&gt; 
     &lt;FirstName&gt;Joe&lt;/FirstName&gt; 
     &lt;LastName&gt;Black&lt;/LastName&gt; 
  &lt;/ShipAddress&gt; 
  &lt;/AlbumOrderItem&gt;
  &lt;AlbumOrderItem&gt; 
     &lt;PartnerCode&gt;ABC Company&lt;/PartnerCode&gt; 
     &lt;AffiliateCode&gt;abcpro&lt;/AffiliateCode&gt; 
     &lt;PartnerOrderID&gt;449&lt;/PartnerOrderID&gt; 
     &lt;PartnerOrderItemID&gt;2&lt;/PartnerOrderItemID&gt; 
     &lt;DateTime&gt;03/14/2013 12:16 AM&lt;/DateTime&gt;  
     &lt;ProductCategory&gt;CARD&lt;/ProductCategory&gt;  
     &lt;Quantity&gt;1&lt;/Quantity&gt; 
     &lt;Package&gt;10&lt;/Package&gt; 
     &lt;NumPrints&gt;10&lt;/NumPrints&gt; 
  &lt;ShipAddress&gt; 
     &lt;FirstName&gt;Joe&lt;/FirstName&gt;
     &lt;LastName&gt;Black&lt;/LastName&gt; 
  &lt;/ShipAddress&gt; 
  &lt;/AlbumOrderItem&gt; 
  &lt;/AlbumOrder&gt;
  </code></pre>
  
  <p>I am currently working with the file below but it doesn't seem to apply the desired changes.  It seems to just produce a full duplicate of the original XML probably based
  on the default XSL template/rules. I'm not sure if there are syntax issues below especially with the template match parameters. I'm also not sure how to search or loop 
  through all of the ProductCategory elements in the entire XML file. If you have any questions please let me know.  Any help would be greatly appreciated in order to add nodes to AlbumOrderItem if ProductCategory is equal to ALBUM and to account for multiple AlbumOrderItems sections.    </p>
  
  <p>Current XSL script</p>
  
  <pre><code> &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
   &lt;xsl:param name="TESTname"&gt;PACK_TEST&lt;/xsl:param&gt;
   &lt;xsl:param name="TESTvalue"&gt;&lt;xsl:value-of select="AlbumOrder/AlbumOrderItem/Package"/&gt;
   &lt;/xsl:param&gt;
  
   &lt;xsl:output method="xml"/&gt;
   &lt;xsl:template match="node()|@*"&gt;
   &lt;xsl:copy&gt;
   &lt;xsl:apply-templates select="node()|@*"/&gt;
   &lt;/xsl:copy&gt;
   &lt;/xsl:template&gt;
  
   &lt;xsl:template match="AlbumOrderItem[ProductCategory=Album]"&gt;
   &lt;xsl:element name="{$TESTname}"&gt;&lt;xsl:value-of select="$TESTvalue"/&gt;&lt;/xsl:element&gt;
   &lt;xsl:apply-templates select="node()|@*"/&gt;
   &lt;/xsl:template&gt;
   &lt;/xsl:stylesheet&gt;  
  </code></pre>