INPUT XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap ="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header xmlns="http://www.ama.net/1axml-msg/schema/msg-header-1_0.xsd">
<MessageHeader ResponseRequested="true" version="1.0" Terminate="true" Reverse="true" id="09B5581A" soap:mustUnderstand="1">
<From>1ASI</From>
<To>1ASRINSAIG</To>
<TimeStamp>
<GenerationTime>2014-10-22T12:41:38Z</GenerationTime>
</TimeStamp>
</MessageHeader>
</soap:Header>
<soap:Body>
<PricingRequest xmlns="http://www.ama.net">
<originatorSection>
<deliverySystem>
<companyId>1A</companyId>
<cityCode>MUC</cityCode>
</deliverySystem>
</originatorSection>
</PricingRequest>
</soap:Body>
</soap:Envelope>
XSLT尝试:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.ama.net/1axml-msg/schema/msg-header-1_0.xsd"
xmlns:ns2="http://www.ama.net" exclude-result-prefixes="ns1 ns2 soap">
<xsl:template match="ns1:* | ns2:*| soap:*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="SOAPHeader">
<xsl:apply-templates select="/soap:Envelope/soap:Header/node()" />
</xsl:variable>
From (Working):<xsl:copy-of select="/soap:Envelope/soap:Header/ns1:MessageHeader/ns1:From/text()"/>
From from $SOAPHeader (Not Working)::<xsl:copy-of select="$SOAPHeader/ns1:MessageHeader/ns1:From/text()"/>
ResponseRequested (NOT Working): <xsl:value-of select="/soap:Envelope/soap:Header/ns1:MessageHeader/@ns1:ResponseRequested"/>
ResponseRequested from $SOAPHeader (Not Working): <xsl:value-of select="$SOAPHeader/ns1:MessageHeader/@ns1:ResponseRequested"/>
</xsl:template>
</xsl:stylesheet>
OUTPut获取:
<?xml version="1.0"?>
From (Working):1ASI
From(Not Working)::
答案 0 :(得分:2)
您在创建SOAPHeader
变量时从元素中剥离命名空间,因此从XPath中删除前缀...
<xsl:copy-of select="$SOAPHeader/MessageHeader/From/text()"/>
和
<xsl:value-of select="$SOAPHeader/MessageHeader/@ResponseRequested"/>
此外,如果您只获得了所显示的输出,并且您没有得到任何&#34; ResponseRequest&#34;文本,可能是您将XSLT作为1.0版运行(您xsl:stylesheet
元素中没有版本)。在1.0中,您不能在路径表达式中使用结果树片段而不使用扩展函数(如exsl:node-set()
)。