Xml 修改SOAP信封
我是XSLT新手,不知道如何更改XMLSOAP消息以在两者之间添加更多标记 源XML:Xml 修改SOAP信封,xml,xslt,soap,peoplesoft,Xml,Xslt,Soap,Peoplesoft,我是XSLT新手,不知道如何更改XMLSOAP消息以在两者之间添加更多标记 源XML: 1234 测试误差 试试这样的方法 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas
1234
测试误差
试试这样的方法
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ex="http://sample.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/*">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>HardCoded Value</faultcode>
<faultstring>HardCoded Value</faultstring>
<xsl:copy-of select="soapenv:Body/ex:DataValidationFailureFault"/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
硬编码值
硬编码值
以一个字母开头。然后,在正确的位置编写另一个模板来干预身份复制过程,即处理soapenv:Body
元素时
XSLT样式表
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="soapenv:Body">
<xsl:copy>
<soapenv:Fault>
<faultcode>HardCoded Value</faultcode>
<faultstring>HardCoded Value</faultstring>
<detail>
<xsl:apply-templates select="@*|node()"/>
</detail>
</soapenv:Fault>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
并修改XSLT代码的样式表
元素,以包含示例:
前缀的名称空间声明,并排除此前缀,因为它在输出中未使用
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sample="http://sample.com"
exclude-result-prefixes="sample">
谢谢Saurav,它很管用。我一直在使用类似的方法,但我使用的是match=“/”,它不起作用。如果使用/*而不是普通/?@Kabudles“/”表示XML中的所有节点,“/*”仅表示XML中的元素节点,这意味着什么xml@Saurav不是真的/
由于模板匹配意味着文档节点(XML树的最外层节点),/*
意味着包含其他所有内容的最外层元素节点。@Kabudles/
由于上面模板的模板匹配部分起作用,它会生成信封
、正文
和错误
。但是的副本不返回任何内容,因为Body
不是最外层的元素。如果将其更改为xsl:copy of select=“soapenv:Envelope/soapenv:Body/ex:DataValidationFailureFault”
或xsl:copy of select=“//ex:DataValidationFailureFault”
则有效。当然,我不能评论你们的“类似方法”。谢谢你们的帮助。这是我第一次在社区网站上写作,我从不后悔。谢谢Mathias Muller,这种方法也很有效。我不熟悉名称空间,但Peoplesoft在创建soap信封时会自动生成这些名称空间。@Kabudles欢迎您。请别忘了(不一定是我的)。谢谢嗨,Mathias-我很好奇如何删除DataValidationFailureFault标记中的名称空间?@Kabudles一起删除它?(所有DataValidationFailureFault
的子元素也带有此默认名称空间)。@Kabudles请查看对我的答案的编辑,或在此处联机尝试:。如果你有更多的问题,我建议你开始一个新的问题帖子,这样就不会太长。
<xsl:template match="sample:DataValidationFailureFault|sample:DataValidationFailureFault//*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sample="http://sample.com"
exclude-result-prefixes="sample">