我正在开发一个应用程序,并且需要将多个元素添加到我收到的肥皂消息的标题中。问题是我不知道我用来添加这些元素的名称空间是使用哪个前缀,但是它确定在正文中会有几个元素使用这个前缀,所以名称空间已经在消息中声明。获取命名空间的前缀
例如,我收到此消息:
<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']'这样的尴尬(低效!)表达式。 –