2015-01-08 4 views
1

응용 프로그램을 개발 중이며받는 SOAP 메시지 헤더에 여러 요소를 추가해야합니다. 문제는이 요소를 추가하기 위해 사용하고있는 네임 스페이스 접두사가 어떤 접두어인지 모르겠지만 네임 스페이스가 이미 메시지에 선언되어 있으므로이 접두사를 사용하여 본문에 여러 요소가있을 것이라는 점은 확실합니다. 예를 들어네임 스페이스 접두사 가져 오기

, 나는이 메시지를 수신하고 있습니다 :

<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으로 선언되었습니다.

제발 도와 주시겠습니까?

+0

귀하의 질문은 ESP, 명확하지 않다. 이 부분은 다음과 같습니다. "* 문제는이 요소를 추가하기 위해 사용하고있는 네임 스페이스가 어떤 접두어를 사용하고 있는지 알 수 없다는 것입니다. *". 일반적으로 접두어는 중요하지 않습니다. 입력 및 출력 모두에서 중요한 것은 자체적으로 네임 스페이스 (URI)입니다. 만약 당신이 이것들을 안다면, 당신은 알아야 할 모든 것을 알기 때문에'* [local-name() = 'Header']와 같은 어색한 (그리고 비효율적 인) 표현을 피할 수 있습니다. –

답변

1

<xsl:value-of select="substring-before(name(//*[namespace-uri() = 'urn:enterprise.soap.sforce.com']), ':')" />과 같은 바보 같은 해결 방법이 사용자의 필요에 부합한다고 생각합니다.

따라서 템플릿 그런 식으로 rewrited 할 수 있습니다

<xsl:template match="*[local-name()='Header']"> 
    <!-- this will retrieve the namespace prefix in source document --> 
    <xsl:variable name="ns-sforce"> 
     <xsl:value-of select="substring-before(name(//*[namespace-uri() = 'urn:enterprise.soap.sforce.com']), ':')" /> 
    </xsl:variable> 

     <xsl:copy> 
     <!-- create prefixed elements with the same value as before --> 
     <xsl:element name="{$ns-sforce}:SH" namespace="urn:enterprise.soap.sforce.com"> 
      <xsl:element name="{$ns-sforce}:sed" namespace="urn:enterprise.soap.sforce.com"> 
      <xsl:value-of select="$Getsed"/> 
      </xsl:element> 
     </xsl:element> 

     <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

참고 : <xsl:template match="//*[local-name()='Header']"> can be replaced by <xsl:template match="*[local-name()='Header']">

+0

도움을 주셔서 감사합니다. 미안하지만 내 자신의 평판이 15에 미치지 못하는만큼이 대답을 유용하게 사용할 수는 없습니다. – ingenierocps

관련 문제