我的要求是使用xslt从输入消息中获得预期输出。 我正在使用的xslt已提供审查.. 输入消息:
<soapenv:Envelope xmlns:v2="http://service..com/esbd/customer/customerlookup/v2"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schema..com/esbd//esbSubHeader/v1">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
soapenv:mustUnderstand="0">
<wsse:UsernameToken>
<wsse:Username></wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
1</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
**<base:TrackingInfo xmlns:base="http://base.canonical.something.com/">
<ApplicationId>BMW</ApplicationId>
<MessageID>112</MessageID>
<CorrelationID>2356260273</CorrelationID>
</base:TrackingInfo>**
</soapenv:Header>
<soapenv:Body>
<web:lookUpCustomer xmlns:web="http://webservices.service.something.com/">
<arg0>
<BirthDttm />
</arg0>
</web:lookUpCustomer>
</soapenv:Body>
</soapenv:Envelope>
expected output :
<soapenv:Envelope xmlns:v1="http://schema.something.com/esbd/esbSubHeader/v1"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v2="http://service.something.com/esbd/customer/customerlookup/v2">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="0"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>something</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
something1</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
**<TrackingInfo>
<ApplicationId >
BMW</ApplicationId>
<MessageID >
112</MessageID>
<CorrelationID >
2356260273</CorrelationID>
</TrackingInfo>**
</soapenv:Header>
<soapenv:Body>
<web:lookUpCustomer xmlns:web="http://webservices.service.something.com/">
<arg0>
<BirthDttm />
</arg0>
</web:lookUpCustomer>
</soapenv:Body>
</soapenv:Envelope>
我正在尝试使用以下xslt
获取输出<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:base=""http://base.canonical.something.com/""
xmlns:v2="http://service.something.com/esbd/owg/customer/customerlookup/v2"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schema.something.com/esbd/owg/esbSubHeader/v1"
exclude-result-prefixes="base v2 v1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="base:*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="namespace::*[not(. = namespace-uri(..))]"/>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
but instead of getting expected output getting below O/P message
<soapenv:Envelope xmlns:v1="http://schema.something.com/esbd/esbSubHeader/v1"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v2="http://service.something.com/esbd/customer/customerlookup/v2">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="0"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>something</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
something1</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
**<TrackingInfo>
<ApplicationId xmlns:base="http://base.canonical.something.com/">
BMW</ApplicationId>
<MessageID xmlns:base="http://base.canonical.something.com/">
112</MessageID>
<CorrelationID xmlns:base="http://base.canonical.something.com/">
2356260273</CorrelationID>
</TrackingInfo>**
</soapenv:Header>
<soapenv:Body>
<web:lookUpCustomer xmlns:web="http://webservices.service.something.com/">
<arg0>
<BirthDttm />
</arg0>
</web:lookUpCustomer>
</soapenv:Body>
</soapenv:Envelope>
有人可以帮我找出我错的地方......
答案 0 :(得分:0)
在XML中,前缀base
绑定到URI:
"http://base.canonical.something.com/"
您的样式表将其绑定到:
"http://base.canonical.owg.walgreens.com/"
出于这个原因,模板:
<xsl:template match="base:*">
不匹配,默认的身份转换模板应用于名称以base
前缀开头的元素。
修复后,您应该获得预期的输出。请注意指令:
<xsl:copy-of select="namespace::*[not(. = namespace-uri(..))]"/>
是不必要的。
另请注意:
<ApplicationId xmlns:base="http://base.canonical.something.com/">BMW</ApplicationId>
与完全相同:
<ApplicationId>BMW</ApplicationId>
如果您对冗余命名空间声明(只有某些处理器将从原始处理器复制)感到烦恼,请在样式表中再添加一个模板:
<xsl:template match="*[not(namespace-uri())]">
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
或将现有的扩展到:
<xsl:template match="base:* | *[not(namespace-uri())]">
<xsl:element name="{local-name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
但所有这些只是化妆品:生成的XML在语义上与未经过这些更改时收到的XML相同。