2017-04-10 4 views
2

다음 XML을 내가 만든 XSLT 스타일 시트를 사용하여 다른 XML 문서로 변환하려고 시도했습니다. 출력물이 내가 원하는 것을 제공하지 않는다. 출력은 올바른 XML 노드가 아니며 태그를 출력하지도 않는다.XSLT를 정의하여 XML을 XML로 변환

누군가 도와 드릴 수 있습니다. 변환 할

XML 파일은 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
     <Extract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <Header> 
      <SubscriptionName>Auto_Clients</SubscriptionName> 
      <SubscriptionID>1731</SubscriptionID> 
      <ExecutionID>11987</ExecutionID> 
      <ODIFeed>Clients</ODIFeed> 
      <DataDateTime>2013-07-22T13:53:49</DataDateTime> 
      <FirmCodes> 
      <FirmCode>ZR</FirmCode> 
      </FirmCodes> 
      <Environment>INTEGRATION</Environment> 
      <NoOfRecords>1</NoOfRecords> 
      </Header> 
      <Clients> 
      <Client> 
      <FirmCode>ZR</FirmCode> 
      <ClientReference>ZR1071049</ClientReference> 
      <ClientType>02</ClientType> 
      <ShortName>ZRTEST</ShortName> 
      <FullName>CLTTEST</FullName> 
      </Client> 
      </Clients> 
     </Extract> 

내가 만든 XSLT 스타일 시트이

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 
     <xsl:template match="table"> 
     <Clients> 
      <xsl:for-each select="Client"> 
      <Client> 
      <FirmCode> 
       <xsl:value-of select="FirmCode" /> 
      </FirmCode> 
      <ClientReference> 
       <xsl:value-of select="ClientReference" /> 
      </ClientReference> 
      <ClientType> 
       <xsl:value-of select="ClientType" /> 
      </ClientType> 
      <ShortName> 
       <xsl:value-of select="ShortName" /> 
      </ShortName> 
      <FullName> 
       <xsl:value-of select="FullName" /> 
      </FullName> 
     </Client> 
     </xsl:for-each> 
     </Clients> 
    </xsl:template> 
    </xsl:stylesheet> 

내 원하는 출력 뭔가 같은 :

<Clients> 
     <Client> 
     <FirmCode>ZR</FirmCode> 
     <ClientReference>ZR1071049</ClientReference> 
     <FullName>CLTTEST</FullName> 
     </Client> 
    </Clients> 

답변

3

입력 내용에 table 요소가 없으므로 템플릿과 일치하지 않습니다. d는 결코 실행되지 않습니다. 당신이 보는 것은 순전히 built-in template rules을 적용한 결과입니다. 변경 또한

<xsl:template match="Extract"> 

:

<xsl:for-each select="Client"> 

에 :

<xsl:for-each select="Clients/Client"> 
<xsl:template match="table"> 

에 :

당신은 변경해야 ClientExtract의 하위가 아니기 때문에입니다.

+0

출력을 변경하지 않았습니다. 어떤 이유로 출력이 텍스트이고, 모든 노드 데이터가 출력되는 노드뿐 아니라 관심있는 노드도 출력됩니다. 또한 태그도 출력되지 않습니다. – DBoyDev

+0

@DBoyDev 여기서 볼 수 있습니다. http://xsltransform.net/naZXpWx –

+0

아니요, 문제는 다른 것입니다. http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work- until-i-remove-root-node/34762628 # 34762628 –