The XPath query and XPath transform are a different things. The XPath in the XPath transform is used as a node test.
It is evaluated in the following way:

Quote

1. Initialize an XPath evaluation context by setting the initial node equal to the input XML document's root node, and set the context position and size to 1.
2. Evaluate the XPath expression (//. | //@* | //namespace::*)

So, the final XPath expression will look like: "(//. | //@* | //namespace::*)[XXX]"
Where XXX is your query "ancestor-or-self::*[@ID='Document_1']".
So it will select all elements in this xml document, and on verification it would select a newly created Signature element, so that's why verification would fail.

Try to set XPath to something like this:
count(ancestor-or-self::*[local-name() = 'document']) > 0

Quote

I even tried to assign ref1.DigestValue manually, but in the resulting XML it was stil wrong.

If you set DigestValue manually, then you shouldn't call UpdateDigestValue method.

Thank you for your quick response. I have revised my code and found one flaw. With manually setting DigestValue it works fine now. Albeit I did not call method UpdateDigestValue in my AddReference() method, but I called UpdateReferencesDigest() in my Sign() method. This was my mistake.
But still I would like to know how to assign XPath transform correctly. Could you give me more detailed explanation how to create an XPath transformation?

Does my way of assigning XPath transform is wrong? I did not understand how it should look. Now I am doing this as follows:

Do I need to set anything else here? I set such (ancestor-or-self::*[@ID='Document_1']) XPath expression because I want to be exactly like this in the signature.xml file under the <Transform ...><XPath> tag. This is an example how the resulting xml's part should look like:

I revised this. Your XPath expression should be correct, but there is a bug in XPath engine in attribute comparison, it invalidly select some nodes.
This is fixed for the next build.
Thank you for pointing this.

We use cookies to help provide you with the best possible online experience. By using this site, you agree that we may store and access cookies on your device. You can find out more about and set your own preferences here.