XSLT从SOAP消息体中获取XML

时间:2011-11-09 22:10:32

标签: xslt soap

我试图弄清楚如何从soap消息的主体中获取所有内容,包括XML标记。

这是我到目前为止所做的:

<?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
        xmlns:soap="http://soap/envelope/"
    >
    <xsl:output method="xml" indent="no"/>

    <xsl:template match="//soap:Body/*">
    </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:4)

以下样式表:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:m="http://www.example.org/stock">
    <xsl:template match="/">
        <xsl:apply-templates select="soap:Envelope/soap:Body/*"/>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

从维基百科申请this SOAP example

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header></soap:Header>
    <soap:Body>
        <m:GetStockPrice xmlns:m="http://www.example.org/stock">
            <m:StockName>IBM</m:StockName>
        </m:GetStockPrice>
    </soap:Body>
</soap:Envelope>

输出SOAP正文的内容(不包括body元素本身):

<m:GetStockPrice xmlns:m="http://www.example.org/stock" 
                 xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <m:StockName>IBM</m:StockName>
</m:GetStockPrice>