我正试图用xades4j签署一个ubl2.1,但我需要排除一些被签署的标签。我使用了xpathtransform,但结果摘要无效。
这是我试图签署的ubl文档(为简单起见,不是完整的文档)
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent>
<sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
<sac:SignatureInformation>
<cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
<sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
</sac:SignatureInformation>
</sig:UBLDocumentSignatures>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
<cbc:ProfileID>reporting:1.0</cbc:ProfileID>
<cbc:ID>20210000011041000001</cbc:ID>
<cbc:UUID>7c0925c8-5536-4b73-aeca-e833f3f78b3c</cbc:UUID>
<cbc:IssueDate>2021-03-14</cbc:IssueDate>
<cbc:InvoiceTypeCode name="01000">380</cbc:InvoiceTypeCode>
<cbc:Note>Some Notes</cbc:Note>
<cbc:DocumentCurrencyCode>USD</cbc:DocumentCurrencyCode>
<cbc:TaxCurrencyCode>USD</cbc:TaxCurrencyCode>
<cac:OrderReference />
<cac:BillingReference>
<cac:InvoiceDocumentReference />
</cac:BillingReference>
<cac:ContractDocumentReference />
<cac:AdditionalDocumentReference>
<cbc:ID>ICV</cbc:ID>
<cbc:UUID>20210000011041000001</cbc:UUID>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>PIH</cbc:ID>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">X+zrZv/IbzjZUnhsbWlsecLbwjndTpG0ZynXOif7V+k=</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>QR</cbc:ID>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">AUrYp9mE2LTYsdmD2Kkg2KfZhNi52LHYqNmK2Kkg2KfZhNmK2YXZhtmK2Kkg2YTZhNin2LPZhdmG2Kog2KfZhNmF2K3Yr9mI2K/YqQIJMTAwMzMxMDMzAxMyMDIxLTAzLTE0MDA6MDA6MDBaBAY0MjU0MDAFATAGQDIyMjk5YjQ0MTU2MDQ0MjYyMzU0YjkzZThhZjNjZThlMjFkNjRjNWVkZWYyZTkxMjk3OTMzNjllM2Y1YmE1MWEHBUVDRHNhWpWNMRzpzfaMmZhfH4APF155H+Fp5LU9xW0umMbEoS47hWKjcYlakCn6Xhx7Ok6iDSN4syJQVaWfAwmARtM1nw==</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
<cac:Signature>
<cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
<cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
</cac:Signature>
</Invoice>
我想从签名中排除这些元素:
//ancestor-or-self::ext:UBLExtensions
//ancestor-or-self::cac:Signature
//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR']
因此,我使用了以下xpath转换
DataObjectDesc obj = new DataObjectReference("")
.withTransform(new XPathTransform("not(//ancestor-or-self::ext:UBLExtensions)"))
.withTransform(new XPathTransform("not(//ancestor-or-self::cac:Signature)"))
.withTransform(new XPathTransform("not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])"))
.withDataObjectFormat(new DataObjectFormatProperty("text/xml"));
但是,结果摘要无效。
提前谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!