title: How to add properly xml transformations to sign file
body: <p>I'm looking for a way to add properly transformations to a xml file.
  How can I add multiple transfomation references? And how to add the Xpath? Is the only way to create a workaround like in example from MS XmlDsigXPathTransform()?</p>
  <p>Right now I'm stuck with this results...</p>
  <pre><code>&lt;SignedInfo&gt; 
  &lt;CanonicalizationMethod Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;/&gt;    
  &lt;SignatureMethod Algorithm=&quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot;/&gt;
  &lt;Reference URI=&quot;&quot;&gt;
  &lt;Transforms&gt;
  &lt;Transform Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#enveloped-signature&quot;/&gt;
  &lt;/Transforms&gt;
  &lt;DigestMethod Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#sha1&quot;/&gt;
  &lt;DigestValue&gt;Ayy6snX6abDJlYYDOOIID+336U0=&lt;/DigestValue&gt;
  &lt;/Reference&gt; 
  &lt;/SignedInfo&gt;
  </code></pre>
  <p>My goal looks like...</p>
  <pre><code>&lt;ds:SignedInfo&gt;
  &lt;ds:CanonicalizationMethod Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;/&gt;
  &lt;ds:SignatureMethod Algorithm=&quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot;/&gt;
  &lt;ds:Reference URI=&quot;&quot;&gt;
  &lt;ds:Transforms&gt;
  &lt;ds:Transform Algorithm=&quot;http://www.w3.org/TR/1999/REC-xpath-19991116&quot;&gt;
  &lt;ds:XPath&gt;not(ancestor-or-self::ds:Signature)&lt;/ds:XPath&gt;
  &lt;/ds:Transform&gt;
  &lt;/ds:Transforms&gt;
  &lt;ds:DigestMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#sha256&quot;/&gt;
  &lt;ds:DigestValue&gt;OVzdad0Jx2/mXIo9bJKw2gqbFaDUGk7Ynkb4UqQO6Jg=&lt;/ds:DigestValue&gt;
  &lt;/ds:Reference&gt;
  &lt;ds:Reference URI=&quot;#SignedProps-72773545-b03c-49fe-98ed-477a2f199934&quot; 
  Type=&quot;http://uri.etsi.org/01903#SignedProperties&quot;&gt;
  &lt;ds:Transforms&gt;
  &lt;ds:Transform Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;/&gt;
  &lt;/ds:Transforms&gt;
  &lt;ds:DigestMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#sha256&quot;/&gt;
  &lt;ds:DigestValue&gt;gVfs0iflUlYKTLHHZYReww4bhWd8tpj4cNMa4ggZ4Mk=&lt;/ds:DigestValue&gt;
  &lt;/ds:Reference&gt;
  &lt;/ds:SignedInfo&gt;
  </code></pre>
  <p>And my Code... Right now it gives me error 'NodeList' on ComputeSignature(), if I use only one reference it signs the file just like above.</p>
  <pre><code>private static void SignXMLDocument(string xmlpath, X509Certificate2 certificate, string signedXMLPath)
      {
          // Load xmlDocument data in to an XML Document
          XmlDocument xmlDocument = new XmlDocument();
          xmlDocument.PreserveWhitespace = false;
  
          xmlDocument.Load(xmlpath);
  
          // Sign the XML document using the certificate private key
          using (var rsaKey = certificate.PrivateKey)
          {
              var signedXml = new SignedXml(xmlDocument);
  
              signedXml.SigningKey = rsaKey;
              signedXml.SignedInfo.SignatureMethod = &quot;http://www.w3.org/2001/04/xmldsig-more#rsa-sha256&quot;;
              signedXml.SignedInfo.CanonicalizationMethod = &quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;;
  
              Reference reference = new Reference();
              reference.Uri = &quot;&quot;;
              XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
              reference.AddTransform(env);
  
              signedXml.AddReference(reference);
  
              Reference reference2 = new Reference();
              reference2.Uri = &quot;&quot;;
              XmlDsigXPathTransform xmldsig = new XmlDsigXPathTransform();
              reference2.AddTransform(xmldsig);
  
              signedXml.AddReference(reference2);
  
              KeyInfo keyInfo = new KeyInfo();
              KeyInfoX509Data kdata = new KeyInfoX509Data(certificate); 
  
              X509IssuerSerial xserial;
  
              xserial.IssuerName = certificate.IssuerName.ToString();
              xserial.SerialNumber = certificate.SerialNumber;
  
              kdata.AddIssuerSerial(xserial.IssuerName, xserial.SerialNumber);
  
              keyInfo.AddClause(kdata);
  
              signedXml.KeyInfo = keyInfo;
  
              signedXml.ComputeSignature();
  
              var xmlDigitalSignature = signedXml.GetXml();
  
              xmlDocument.DocumentElement.AppendChild(xmlDocument.ImportNode(xmlDigitalSignature, true));
  
              xmlDocument.Save(signedXMLPath);
          }
      }
  </code></pre>