Q: XSLT1.0 copy all nodes and add node I have xml and I want to copy it and add one more element if it is not there. There are similar elements QTY and I want to look at the value of element C186 / E6063. But my XSLT doesn't work.I think I was wrong about xpath, but where?
Input XML
 <?xml version="1.0" encoding="utf-8"?>
<root>
    <InterchangeHeader>InterchangeHeader</InterchangeHeader>
    <SG0>
        <UNH>UNH</UNH>
        <BGM>BGM</BGM>
        <DTM>DTM</DTM>
        <SG26>
            <LIN>
                <E1082>000010</E1082>
                <C212>
                    <E7143>SRV</E7143>
                </C212>
            </LIN>
            <PIA>
                <E4347>1</E4347>
                <C212>
                    <E7140>000010</E7140>
                    <E7143>IN</E7143>
                </C212>
            </PIA>
            <QTY>
                <C186>
                    <E6063>21</E6063>
                    <E6060>2100.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
            <QTY>
                <C186>
                    <E6063>170</E6063>
                    <E6060>2100.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
        </SG26>
        <SG26>
            <LIN>
                <E1082>000020</E1082>
                <C212>
                    <E7143>SRV</E7143>
                </C212>
            </LIN>
            <PIA>
                <E4347>1</E4347>
                <C212>
                    <E7140>000020</E7140>
                    <E7143>IN</E7143>
                </C212>
            </PIA>
            <QTY>
                <C186>
                    <E6063>21</E6063>
                    <E6060>2100.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
            <QTY>
                <C186>
                    <E6063>170</E6063>
                    <E6060>0.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
        </SG26>
        <SG26>
            <LIN>
                <E1082>000030</E1082>
                <C212>
                    <E7143>SRV</E7143>
                </C212>
            </LIN>
            <PIA>
                <E4347>1</E4347>
                <C212>
                    <E7140>000030</E7140>
                    <E7143>IN</E7143>
                </C212>
            </PIA>
            <QTY>
                <C186>
                    <E6063>21</E6063>
                    <E6060>2100.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
            <QTY>
                <C186>
                    <E6063>170</E6063>
                    <E6060>1900.000</E6060>
                    <E6411>EA</E6411>
                </C186>
            </QTY>
        </SG26>
        <UNS>
            <E0081>S</E0081>
        </UNS>
    </SG0>
    <InterchangeTrailer>InterchangeTrailer</InterchangeTrailer>
</root>

MY XSLT In the first part, I copy everything, and then I try to change
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:ext="urn:ext" exclude-result-prefixes="ext msxml">
    <xsl:output method="xml" indent="yes" encoding="utf-8"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="SG26[not(QTY/C186/E6063='59')]">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <QTY>
                <C186>
                    <E6063>59</E6063>
                    <E6060>
                        <xsl:value-of select="'1'"/>
                    </E6060>
                    <E6411>
                        <xsl:value-of select="'2'"/>
                    </E6411>
                </C186>
            </QTY>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Desired XML result I would like to add one more  element, but without affecting the other  elements that are already there. The order of the elements is not important.
...
<SG26>
    <QTY>
        <C186>
            <E6063>21</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>170</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>59</E6063>
            <E6060>1</E6060>
            <E6411>2</E6411>
        </C186>
    </QTY>
    ...
</SG26>
<SG26>
    <QTY>
        <C186>
            <E6063>21</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>170</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>59</E6063>
            <E6060>1</E6060>
            <E6411>2</E6411>
        </C186>
    </QTY>
    ...
</SG26>
<SG26>
    <QTY>
        <C186>
            <E6063>21</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>170</E6063>
            <E6060>2100.000</E6060>
            <E6411>EA</E6411>
        </C186>
    </QTY>
    <QTY>
        <C186>
            <E6063>59</E6063>
            <E6060>1</E6060>
            <E6411>2</E6411>
        </C186>
    </QTY>
    ...
</SG26>

UPD.
@Martin Honnen Thanks, it works. But I ran into one more problem, if I want to add one more element, then one is removed.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:ext="urn:ext" exclude-result-prefixes="ext msxml">
    <xsl:output method="xml" indent="yes" encoding="utf-8"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="SG26[not(QTY/C186/E6063=59)]">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
            <QTY>
                <C186>
                    <E6063>59</E6063>
                    <E6060>
                        <xsl:value-of select="'status'"/>
                    </E6060>
                    <E6411>
                        <xsl:value-of select="'status'"/>
                    </E6411>
                </C186>
            </QTY>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="SG26[not(QTY/C186/E6063=60)]">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
            <QTY>
                <C186>
                    <E6063>60</E6063>
                    <E6060>
                        <xsl:value-of select="'status2'"/>
                    </E6060>
                    <E6411>
                        <xsl:value-of select="'status2'"/>
                    </E6411>
                </C186>
            </QTY>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>


A: If you really want to copy everything and additionally add that QTY C186 subtree with E6063 being 59 and the other two elements for which you have not spelled out which value you want then I think your code nearly does that, other than not putting the added element last:
  <xsl:template match="SG26[not(QTY/C186/E6063=59)]">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
      <QTY>
        <C186>
          <E6063>59</E6063>
          <E6060>
              <xsl:value-of select="'status'"/>
          </E6060>
          <E6411>
              <xsl:value-of select="'status'"/>
          </E6411>          
        </C186>
      </QTY>
    </xsl:copy>  
  </xsl:template>

It is not clear from your post which wrong result you get or whether your desired output is cut to show the relevant parts or meant to also imply you want to delete some elements.
