Using XSL to extract values from WCF Soap Messages
I am trying to use XSL to transform the following WCF call and place the result in a queue:
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">SendMessage</a:Action>
<a:MessageID>urn:uuid:19034ce7-c5ce-4670-ac6c-cfef30c245bd</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
<s:Body>
<SendMessage xmlns="http://my.custom.namespace/2007/12">
<request xmlns:i="http://www.w开发者_JS百科3.org/2001/XMLSchema-instance">
<to>Test</to>
<from>Test</from>
<message>Test</message>
<service>Test</service>
</request>
</SendMessage>
</s:Body>
</s:Envelope>
What I would like to do is get to the 'to', 'from', 'message', and 'service' nodes, but I am having trouble selecting beyond due to the default namespaces used in the child nodes. Does anyone know the proper xPath query I should be using to get to these nodes?
Thanks,
Mike
What I would like to do is get to the 'to', 'from', 'message', and 'service' nodes, but I am having trouble selecting beyond due to the default namespaces used in the child nodes. Does anyone know the proper xPath query I should be using to get to these nodes?
Use:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:sb="http://my.custom.namespace/2007/12">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select=
"/*/s:Body/sb:SendMessage/sb:request/*"/>
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on the provided XML document:
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">SendMessage</a:Action>
<a:MessageID>urn:uuid:19034ce7-c5ce-4670-ac6c-cfef30c245bd</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
<s:Body>
<SendMessage xmlns="http://my.custom.namespace/2007/12">
<request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<to>Test</to>
<from>Test</from>
<message>Test</message>
<service>Test</service>
</request>
</SendMessage>
</s:Body>
</s:Envelope>
the wanted nodes are output:
<to xmlns="http://my.custom.namespace/2007/12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">Test</to>
<from xmlns="http://my.custom.namespace/2007/12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">Test</from>
<message xmlns="http://my.custom.namespace/2007/12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">Test</message>
<service xmlns="http://my.custom.namespace/2007/12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">Test</service>
精彩评论