2014-11-04 3 views
0

변수에 soap : Header 요소의 자식 요소를 모두 복사하려고 시도하고 PricingRequest 빈 네임 스페이스 (xmlns = "http : //www.ama .net ") xml의 PricingRequest 부분 만 출력합니다. PricingRequest 빈 네임 스페이스를 제거하고 적절한 출력을 얻을 수 있지만 soap : Header 자식 요소를 변수에 저장할 수 없다면 soap : Header의 자식 요소를 변수에 복사 할 수 있습니까?자식 노드 네임 스페이스를 제거하고 다른 노드를 변수로 복사

입력 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 version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:x="http://www.ama.net" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 
    <xsl:strip-space elements="*"/> 
<!-- <xsl:template match="/*[local-name()='Envelope']"> 
     <xsl:variable name="SOAPHeader" select="/soap:Header/node()" /> 
     <xsl:text> MessageHeader INFO:<xsl:copy-of select="$SOAPHeader"/> </xsl:text> 
    </xsl:template> --> 

    <xsl:template match="*"> 
     <xsl:element name="{name()}"> 
      <xsl:copy-of select="@*"/> 
      <xsl:apply-templates/> 
     </xsl:element>  
    </xsl:template> 
    <xsl:template match="*[not(ancestor-or-self::x:PricingRequest)]"> 
     <xsl:apply-templates/> 
    </xsl:template> 

</xsl:stylesheet> 

비누를 복사 할 수 OUTPUT을 기대하지만 점점

<PricingRequest> 
    <originatorSection> 
    <deliverySystem> 
     <companyId>1A</companyId> 
     <cityCode>MUC</cityCode> 
    </deliverySystem> 
    </originatorSection> 
</PricingRequest> 
+0

: 헤더 * "하지만 당신은 비누의 자손 인 몸을 보여주고 있습니다. –

+0

안녕 마이클, 제 질문을 찾아 주셔서 고맙습니다. 위의 xslt는 내가 찾고있는 XML 출력을 얻을 수 있으며 로깅 목적을 위해 모든 요소와 속성을 soap : Header 내부에 인쇄해야합니다. 내 xslt 보면, 주석 코드에서 무엇을하려고하는지 볼 수 있습니다. 나는 비누 : 헤더와 일치시킬 수 없으며 변수에 내용을 복사한다. – sarma

답변

1

시도;

<xsl:template match="/"> 
    <xsl:variable name="SOAPHeader" select="/soap:Envelope/soap:Header/node()" /> 
    <xsl:text>MessageHeader INFO:</xsl:text> 
    <xsl:copy-of select="$SOAPHeader"/> 
</xsl:template> 

:

  1. <xsl:text> 자식 요소를 포함 할 수 없습니다;
  2. 버전에 soap:Envelope에 대한 충돌 템플릿이 있습니다.
+0

마이클, xsl : text에 대한 정보를 보내 주셔서 감사합니다. 귀하의 코드를 사용하고 초기 질문을 다시 짜 넣었습니다. 네임 스페이스가없는 새 XML로 변환하려고 시도하고 있습니다. 그렇게 할 수 있습니까? – sarma

+1

@sarma 질문을 원본으로 되돌리고 새로운 것을 게시하는 것이 좋습니다 (이 문서를 닫은 후에). –

+0

귀하의 제안에 감사드립니다. 원래 질문으로 되돌아갔습니다. – sarma

0

다음 코드는 내가 원하는대로 작동했습니다. 나는 비누를 복사 할 수 있어요 : 출력에 변수에 헤더의 자식 요소도 제거 PricingRequest 네임 스페이스

<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>   
     <xsl:text>HeaderInfo:</xsl:text> 
     <xsl:copy-of select="$SOAPHeader" /> 
     <xsl:apply-templates select="/soap:Envelope/soap:Body/node()" />  
    </xsl:template> 

</xsl:stylesheet> 

출력 내가 점점 오전 : 당신은 비누 * 복사 자식 요소 "라고

<?xml version="1.0"?> 
HeaderInfo: 
    <MessageHeader xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 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> 

<PricingRequest> 
    <originatorSection> 
     <deliverySystem> 
      <companyId>1A</companyId> 
      <cityCode>MUC</cityCode> 
     </deliverySystem>  
    </originatorSection>  
</PricingRequest> 
관련 문제