2017-03-17 6 views
0

메시지를 변형하고 이전 네임 스페이스를 새 네임 스페이스로 바꾸어야하는 프로젝트에서 작업하고 있습니다. 그 구성 요소가 올바르게 작동합니다. 스키마 속성이 변경되지 않았습니다. 내가 별도로 할 수 있지만 스키마 네임 스페이스 및 요소 네임 스페이스를 변경할 수 없습니다. 내가 여기서 무엇을 놓치고 있니? 여기 XML 메시지 변형은 스키마를 변경하지 않습니다.

메시지이다

여기
<ns1:SupportNotificationMsg xsi:schemaLocation="http://namespace1.com:8081/Organization/SupportServices SupportServices.xsd" 
      xmlns:ns3="http://namespace3.com/Common" 
      xmlns:ns1="http://namespace1.com:8081/Organization/SupportServices" 
      xmlns:ns2="http://namespace2.com:8081/Organization/" 
      xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
      xmlns:j="http://www.it.ojp.gov/jxdm/3.0.3" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <ns2:SupportNotification> 
      <ns3:MessageHeader> 
      <ns3:MessageSender> 
      <ns3:OrganizationName>ORG</ns3:OrganizationName> 
      <ns3:ApplicationName>SEARCH</ns3:ApplicationName> 
      <ns3:ContactName>Support</ns3:ContactName> 
      <ns3:ContactPhoneNumber>111-222-3333</ns3:ContactPhoneNumber> 
      </ns3:MessageSender> 
      <ns3:MessageSentDateTime>2017-03-17T12:14:33</ns3:MessageSentDateTime> 
      </ns3:MessageHeader> 
      <ns2:SupportID>11243</ns2:SupportID> 
      <ns2:IdSetting idKey="123456"> 
      <ns2:IdName ns2:code="APP1">ApplicationName</ns2:IdName> 
      <ns2:IdTypeText ns2:code="HLP">HelpDesk</ns2:IdTypeText> 
      <ns2:Setting settingKey="3091062"> 
      <ns2:SupportDateTimes>2017-03-17T08:30:00-05:00</ns2:SupportDateTimes> 
      <ns2:SupportSettingStatus>Open</ns2:SupportSettingStatus> 
      </ns2:Setting> 
      </ns2:IdSetting> 
    </ns2:SupportNotification> 
</ns1:SupportNotificationMsg > 

인 변환 :

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:NS1="http://namespace1.com:8081/Organization/SupportServices" 
    xmlns:NS2="http://namespace2.com:8081/Organization/" 
    xmlns:NS3="http://namespace3.com/Common" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:strip-space elements="*"/> 
    <xsl:template match="@* | node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="NS1:*"> 
     <xsl:element name="{local-name()}" 
      namespace="http://newnamespace1.com/Organization/SupportServices"> 
      <xsl:attribute name="xsi:schemaLocation">http://newnamespace1.com/Organization/SupportServices SupportServices.xsd</xsl:attribute> 
      <xsl:copy-of select="@*" /> 
      <xsl:apply-templates /> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="NS2:*"> 
     <xsl:element name="{local-name()}" 
      namespace="http://newnamespace2.com/Organization/"> 
      <xsl:copy-of select="@*" /> 
      <xsl:apply-templates /> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="NS3:*"> 
     <xsl:element name="{local-name()}" 
      namespace="http://newnamespace3.com/Common"> 
      <xsl:copy-of select="@*" /> 
      <xsl:apply-templates /> 
     </xsl:element> 
    </xsl:template> 


</xsl:stylesheet> 

를 I가

<xsl:template match="/attribute::xsi:schemaLocation"/> 

또는

<xsl:template match="/@xsi:schemaLocation[. = 'http://namespace1.com:8081/Organization/SupportServices SupportServices.xsd']"> 
    <xsl:attribute name="xsi:schemaLocation">http://newnamespace1.com/Organization/SupportServices SupportServices.xsd</xsl:attribute> 
</xsl:template> 
추가 한

이전 스키마에서도 유효성을 검사 할 수 있지만 필자 만의 최선의 방법으로 변경하고 싶습니다.

어떤 통찰력이라도 대단히 감사합니다.

는 요청에 따라 당신은 당신의 구조를 변환하기 위해 다음과 같은 XSLT를 사용할 수

데이브

+1

문서 노드 /'결코 어떤 속성 (요소 만이 속성이)가 없습니다 그래서 당신은/@의 XSI '와 일치하고 싶은 확실하지 않다 : schemaLocation'에 대한 속성과 일치하도록 노력할 것이다 문서 노드 –

답변

1

을 주셔서 감사합니다. 변형을 설명하기 위해 스타일 시트에 몇 가지 설명을 추가했습니다. 이것이 명확하지 않거나 어떤 식 으로든 점수를 놓친다면 알려주십시오. `으로 선정

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:NS1="http://namespace1.com:8081/Organization/SupportServices" 
    xmlns:NS2="http://namespace2.com:8081/Organization/" 
    xmlns:NS3="http://namespace3.com/Common" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    version="1.0" 
> 

<xsl:output method="xml" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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


<xsl:template match="NS1:*"> 
    <!-- Add element with namespace --> 
    <xsl:element name="ns1:{local-name()}" 
     namespace="http://newnamespace1.com/Organization/SupportServices"> 
      <!-- Copy all of the namespaces from the source xml but exclude 
       the ns1, ns2, ns3 original namespaces from the source xml 
       document --> 
      <xsl:copy-of select="namespace::*[not(name()='ns2') 
       and 
       not(name()='ns3') 
       and 
       not(name()='ns1')]"/> 
     <xsl:apply-templates select="@* | node()"/> 

    </xsl:element> 
</xsl:template>  

<xsl:template match="NS2:*"> 
    <xsl:element name="ns2:{local-name()}" 
     namespace="http://newnamespace2.com/Organization/"> 
     <xsl:apply-templates /> 
    </xsl:element> 
</xsl:template> 

<xsl:template match="NS3:*"> 
    <xsl:element name="ns3:{local-name()}" 
     namespace="http://newnamespace3.com/Common"> 
     <xsl:apply-templates /> 
    </xsl:element> 
</xsl:template> 

<!-- replace xsi:schemaLocation attribute --> 
<xsl:template match="@xsi:schemaLocation"> 
    <xsl:attribute name="xsi:schemaLocation">http://newnamespace1.com/Organization/SupportServices SupportServices.xsd</xsl:attribute> 
</xsl:template>   
</xsl:stylesheet> 
+0

M. Rizzo에게 감사드립니다. 나는 조금만 수정했고 나는 필요한 해결책을 가지고있다. – djratliff