我需要建议来处理带有大量SOAP信封的XML文档,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<Envelopes>
<soapenv:Envelope xmlns:sal="http://fc.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sal:divide>
<arg0>3</arg0>
<arg1>532</arg1>
</sal:divide>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:sal="http://fc.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sal:divide>
<arg0>3</arg0>
<arg1>543</arg1>
</sal:divide>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:sal="http://fc.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sal:divide>
<arg0>3</arg0>
<arg1>553</arg1>
</sal:divide>
</soapenv:Body>
</soapenv:Envelope>
</Envelopes>
我正在寻找一种方法将整个变量放入变量进行解析。
如何使用纯XSL转换实现这一目标? (没有Java代码)
XSL片段:
<xsl:for-each select="/Envelopes/soapenv:Envelope">
<xsl:message terminate="no" dp:priority="info">
SomeUniqueString
</xsl:message>
<xsl:variable name="fc" select="/Envelopes/soapenv:Envelope"/>
<xsl:message terminate="no" dp:priority="info">
<xsl:value-of select="position()"/>
</xsl:message>
<xsl:message terminate="no" dp:priority="info">
<xsl:value-of select="$fc"/>
</xsl:message>
</xsl:for-each>
你可以忽略&#39; dp:&#39;功能...
答案 0 :(得分:1)
有两个问题:
<xsl:for-each>
允许您使用.
访问当前项目。无需在根节点中使用select start。<xsl:copy-of>
而不是<xsl:value-of>
,只需复制文本部分即可展平您的输出。请尝试以下代码:
<xsl:for-each select="/Envelopes/soapenv:Envelope">
<xsl:message terminate="no" dp:priority="info">
SomeUniqueString
</xsl:message>
<!-- introduce a variable for the current envelope -->
<xsl:variable name="fc" select="."/>
<xsl:message terminate="no" dp:priority="info">
<xsl:value-of select="position()"/>
</xsl:message>
<xsl:message terminate="no" dp:priority="info">
<!-- use copy-of the copy the whole envelope to the output -->
<xsl:copy-of select="$fc"/>
</xsl:message>
</xsl:for-each>