2009-07-17 3 views
1

내가 비누 헤더를 추가 - 노드를 업데이트 - 문서

<Rs xmlns="http://tempuri.org/schemas"> 

문서 노드의 나머지 부분을 복사하는 모든 동안 함께 최초의 RS 노드를 내 문서에 비누 헤더를 추가하고 업데이트하기 위해 노력하고있어 복사합니다. 내 실제 예제에서 RS 부모 노드 내에서 더 많은 노드를 갖게 될 것이므로 나는 일종의 완전한 복사본을 가진 솔루션을 찾고있다.

<-- this is the data which needs transforming --> 

<Rs> 
    <ID>934</ID> 
    <Dt>995116</Dt> 
    <Date>090717180408</Date> 
    <Code>9349</Code> 
    <Status>000</Status> 
</Rs> 


<-- Desired Result --> 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
<SOAP-ENV:Body> 
    <Rs xmlns="http://tempuri.org/schemas"> 
    <ID>934</ID> 
    <Dt>090717180408</Dt> 
    <Code>9349</Code> 
    <Status>000</Status>  
    </Rs> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

<-- this is my StyleSheet. it's not well formed so i can't exexute it--> 

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 
<xsl:output method="xml" indent="yes" encoding="UTF-8"/> 
<xsl:template match="/"> 
    <SOAP-ENV:Envelope 
       xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
     <SOAP-ENV:Body> 
        <xsl:apply-templates select = "Rs"> 
        </xsl:apply-templates> 
        <xsl:copy-of select="*"/> 
     </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 
</xsl:template> 
<xsl:template match ="Rs"> 
    <Rs xmlns="http://tempuri.org/schemas"> 
</xsl:template> 
</xsl:stylesheet> 

저는 튜토리얼을 읽었지만 템플리트를 고민하고 구현할 때 문제가 있습니다.

+0

XSL은 사소하지 않습니다. 내가 너라면 좀 더 간단하게 시작할거야. –

답변

1

xmlns은 다른 속성 일뿐만 아니라 네임 스페이스 변경을 나타냅니다. 그래서 좀 더 까다 롭습니다. 이 시도 : 당신이 indent="yes"를 사용하지 않는하지만 난 그게 가능한 한 밀접하게 출력과 일치 만들려고하면

<?xml version='1.0' ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/> 
    <xsl:template match="/"> 
     <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
      <SOAP-ENV:Body> 
       <xsl:apply-templates select="Rs"/> 
      </SOAP-ENV:Body> 
     </SOAP-ENV:Envelope> 
    </xsl:template> 
    <xsl:template match="node()"> 
     <xsl:element name="{local-name(.)}" namespace="http://tempuri.org/schemas"> 
      <!-- the above line is the tricky one. We can't copy an element from --> 
      <!-- one namespace to another, but we can create a new one in the --> 
      <!-- proper namespace. --> 
      <xsl:copy-of select="@*"/> 
      <xsl:apply-templates select="node()|*"/> 
     </xsl:element> 
    </xsl:template> 
    <xsl:template match="text()"> 
     <xsl:if test="normalize-space(.) != ''"> 
      <xsl:value-of select="."/> 
     </xsl:if> 
    </xsl:template> 
</xsl:stylesheet> 

체조의 일부

그렇게 중요하지 않습니다.

관련 문제