私は次のXMLを持っています(データの多くはダミーです)
<?xml version="1.0" encoding="UTF-8"?>
<msg xmlns="http://someaddress.com/m1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://someaddress/somexsd.xsd">
<header>
<nodeA>aaaaaaaaaaa</nodeA>
<nodeB>bbbbbbbb</nodeB>
</header>
<payload>
<calcnode xmlns="http://someaddress/nodeC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://someaddress/somexsd.xsd">
<somefield>field</somefield>
</calcnode>
<ds:Signature>
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#kjbn34jkb5j-3k45j-k3jb534jkb534k5">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>+se0dfgft9gh8hjuji7ji65ko4ko3ko2</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>sekfrhsdkjfhsdkjfhksd</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>sdjkfhsdkfhskdf</X509Certificate>
</X509Data>
</KeyInfo>
</ds:Signature>
</payload>
</msg>
そして、私がやりたいのは、msg
要素の名前(にnewmsg
)とデフォルトの名前空間をに変更することだけhttp://someaddress.com/m2
です。それ以外はすべてそのままにしておく必要があります。私が得ることができた最も近いものはこのxsltです
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msg="http://someaddress.com/m1" >
<!-- the identity template -->
<xsl:template match="@* | node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<!-- replace namespace of elements in old namespace -->
<xsl:template match="msg:msg">
<xsl:element name="newmsg" namespace="http://someaddress.com/m2">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
テストにxalanを使用しています。これは、上記を実行したときに取得する出力xmlです。
<?xml version="1.0" encoding="UTF-8"?>
<newmsg xmlns="http://someaddress.com/m2" xsi:schemaLocation="http://someaddress/somexsd.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header xmlns="http://someaddress.com/m1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<nodeA>aaaaaaaaaaa</nodeA>
<nodeB>bbbbbbbb</nodeB>
</header>
<payload xmlns="http://someaddress.com/m1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<calcnode xmlns="http://someaddress/nodeC" xsi:schemaLocation="http://someaddress/somexsd.xsd">
<somefield>field</somefield>
</calcnode>
<ds:Signature>
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#kjbn34jkb5j-3k45j-k3jb534jkb534k5">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>+se0dfgft9gh8hjuji7ji65ko4ko3ko2</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>sekfrhsdkjfhsdkjfhksd</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>sdjkfhsdkfhskdf</X509Certificate>
</X509Data>
</KeyInfo>
</ds:Signature>
</payload>
</newmsg>
これには2つの主な問題があります。
- 名前
ds
空間が出力から消えるだけで、理由はわかりません。 xsi
2番目の問題は、から名前空間を削除し、calcnode
がcalcnode
署名の計算(および検証)に使用されるノード(そのセクションの下にあります)であるとすると、そのような変更により、署名の検証が理解できなくなることです。
私はxsltのいくつかの異なる反復を試しましたが、多くの結果は得られませんでした。誰かがその状況に光を当てることができますか?