我正在開發一個應用程序,並且需要將多個元素添加到我收到的肥皂消息的標題中。問題是我不知道我用來添加這些元素的名稱空間是使用哪個前綴,但是它確定在正文中會有幾個元素使用這個前綴,所以名稱空間已經在消息中聲明。獲取命名空間的前綴
例如,我收到此消息:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
<soapenv:Header/>
<soapenv:Body>
<urn:operation>
</urn:operation>
</soapenv:Body>
</soapenv:Envelope>
我用於在首部添加這些元素中的XPath表達式爲:
<xsl:stylesheet version="1.0" exclude-result-prefixes="xsi xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:param name="Getsed">aBcDeFgHiJkLmNñOpQrStUvWxYz</xsl:param>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[local-name()='Header']">
<xsl:copy>
<urn:SH xmlns:urn="urn:enterprise.soap.sforce.com">
<urn:sed><xsl:value-of select="$Getsed"/></urn:sed>
</urn:SH>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我想使用前綴(urn)已經聲明爲命名空間urn:enterprise.soap.sforce.com
。
你能幫我一下嗎?
你的問題不明確,ESP。這部分:「*問題是我不知道我用來添加這些元素的名稱空間是使用哪個前綴,.. *」。通常,前綴不重要 - 在輸入和輸出中,重要的是名稱空間(URI)本身。如果你知道這些,那麼你就知道所有你需要知道的東西,並且你可以避免像'* [local-name()='Header']'這樣的尷尬(低效!)表達式。 –