Here is a simple, concise XSLT 1.0 solution.
When this XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
version="1.0">
<xsl:output omit-xml-declaration="no" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wsu:Created|wsu:Expires">
<xsl:copy>
<xsl:value-of select="concat(substring-before(., 'Z'), '.000Z')" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
...is applied to the originally provided XML:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:dat="http://schemas.datacontract.org/2004/07/DataContracts" xmlns:tem="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-78496158-6fa4-41da-8887-b8116829f1d8">
<wsu:Created>2012-10-12T10:08:42Z</wsu:Created>
<wsu:Expires>2012-10-12T11:13:42Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-db63adf4-d7c7-4827-8c36-56f672e6c397" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">xyz</wsse:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">xyz</Signature>
</wsse:Security>
</soapenv:Header>
</soapenv:Envelope>
...the wanted result is produced:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:dat="http://schemas.datacontract.org/2004/07/DataContracts" xmlns:tem="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-78496158-6fa4-41da-8887-b8116829f1d8">
<wsu:Created>2012-10-12T10:08:42.000Z</wsu:Created>
<wsu:Expires>2012-10-12T11:13:42.000Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-db63adf4-d7c7-4827-8c36-56f672e6c397" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">xyz</wsse:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">xyz</Signature>
</wsse:Security>
</soapenv:Header>
</soapenv:Envelope>
Explanation:
- Template #1 is the
Identity Template
. It's purpose is to copy all nodes and attributes from the source template to the result template as-is.
- Template #2 matches both
<wsu:Created>
and <wsu:Expires>
elements. Upon finding these elements, the XSLT copies them to the result document and alters their values to be the desired values.