2011-07-05 3 views
1

xslt를 사용하여 입력 XML 변환에 대한 지정이 있습니다. 입력 XML 용 XSLT 작성

내 입력 XML 파일

<?xml version="1.0" encoding="UTF-8"?> 
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> 
<rs:data> 
    <z:row ID="1" CK="B0011" Description="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/> 
    <z:row ID="2" CK="B0012" Description="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/> 
    <z:row ID="3" CK="B0013" Description="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP"/> 
    <z:row ID="4" CK="B0014" Description="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/> 
    <z:row ID="5" CK="B0015" Description="VSC_4" DTC="B0014" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/> 
</rs:data> 
</xml> 

는 예외 처리의 XML 출력은 :

<DF> 
<Cage Revision="" RevisionDate="" CPType="Authored" Ext_Identifier=""> 
    <Entities> 
     <StdDTCs> 
      <StdDTC Action="Insert" CK="B0011" Description ="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/> 
      <StdDTC Action="Insert" CK="B0012" Description ="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/> 
      <StdDTC Action="Insert" CK="B0013" Description ="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP"/> 
      <StdDTC Action="Insert" CK="B0014" Description ="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/> 
      <StdDTC Action="Insert" CK="B0015" Description ="VSC_4" DTC="B0014" Variant="" AN="Y" Notes=" " GCategory="M3" System="VOS" Ownership="EEP"/> 
     </StdDTCs> 
     <ABCDs> 
     <ABCD/> 
     ............... 
     ............... 
     ............... 
     <ABCD/> 
     </ABCDs> 
    </Entities> 
</Cage> 
</DF> 

가 나는 XSLT에 조금을 시도했다.

<xsl:key name="UID" match="z:row/@ID" use="."/> 
<xsl:template match="/"> 
    <DF> 
     <Cage> 
      <xsl:attribute name="Revision"><xsl:value-of select="''"/></xsl:attribute> 
      <xsl:attribute name="RevisionDate"><xsl:value-of select="''"/></xsl:attribute> 
      <xsl:attribute name="ChangePackageType"><xsl:value-of select="'Authored'"/></xsl:attribute> 
      <xsl:attribute name="Ext_Identifier"><xsl:value-of select="''"/></xsl:attribute> 
      <xsl:apply-templates select="@*|node()"/> 
     </Cage> 
    </DF> 
</xsl:template> 

<!-- <xsl:template match="rs:data"> 
    <Entities> 
     <StandardDTCs> 
      <xsl:apply-templates select="StandardDTC"/> 
     </StandardDTCs> 
     </Entities> 
</xsl:template> --> 
<xsl:template match="rs:data"> 
<StdDTCs> 
    <StdDTC> 
     <xsl:attribute name="Action"><xsl:value-of select="'Insert'"/></xsl:attribute> 
     <xsl:attribute name="CK"><xsl:value-of select="z:row/@CK"/></xsl:attribute> 
     <xsl:attribute name="Description"><xsl:value-of select="z:row/@Description"/></xsl:attribute> 
     <xsl:attribute name="DTC"><xsl:value-of select="z:row/@DTC"/></xsl:attribute> 
     <xsl:attribute name="Variant"><xsl:value-of select="z:row/@DTC"/></xsl:attribute> 
     <xsl:attribute name="AN"><xsl:value-of select=""/></xsl:attribute> 
     <xsl:attribute name="Notes"><xsl:value-of select=""/></xsl:attribute> 
     <xsl:attribute name="GCategory"><xsl:value-of select=""/></xsl:attribute> 
     <xsl:attribute name="System"><xsl:value-of select=""/></xsl:attribute> 
     <xsl:attribute name="Ownership"><xsl:value-of select=""/></xsl:attribute> 
    </StdDTC> 
</StdDTCs> 
</xsl:template> 
</xsl:stylesheet> 

<?xml version="1.0" encoding="UTF-8"?> 

이 XSLT를 프레임에 저를 도와주세요.

+0

무엇이 당신의 질문입니다. –

+0

ABCD에는 어떤 것이 포함되어야합니까? –

+0

안녕하세요, 모든 5 행을 인쇄 할 수 없습니다. 한 행만 인쇄 할 수 있습니다. ABCD는 StdDTC와 유사합니다. StdDTC를 할 수 있다면 bcoz에 대한 언급을하지 않았고 마찬가지로 ABCD도 할 수 있습니다. 또한, 내 XSLT 원시 XSLT입니다. 어떻게 더 체계적 일 수 있습니까? 감사합니다. – Ramm

답변

2

사용이 (약간 수정 솔루션) :

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset" 
> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 
     <DF> 
      <Cage> 
       <xsl:attribute name="Revision"> 
        <xsl:value-of select="''"/> 
       </xsl:attribute> 
       <xsl:attribute name="RevisionDate"> 
        <xsl:value-of select="''"/> 
       </xsl:attribute> 
       <xsl:attribute name="ChangePackageType"> 
        <xsl:value-of select="'Authored'"/> 
       </xsl:attribute> 
       <xsl:attribute name="Ext_Identifier"> 
        <xsl:value-of select="''"/> 
       </xsl:attribute> 
       <StdDTCs> 
        <xsl:apply-templates select="@*|node()"/> 
       </StdDTCs> 
      </Cage> 
     </DF> 
    </xsl:template> 

    <xsl:template match="rs:data/z:row"> 
     <StdDTC Action="Insert"> 
      <xsl:for-each select="@*"> 
       <xsl:attribute name="{name()}"> 
        <xsl:value-of select="."/> 
       </xsl:attribute> 
      </xsl:for-each> 
     </StdDTC> 
    </xsl:template> 
</xsl:stylesheet> 

출력 : 이것은 내 생각이다

<?xml version="1.0" encoding="utf-8"?> 
<DF xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset"> 
    <Cage Revision="" RevisionDate="" ChangePackageType="Authored" Ext_Identifier=""> 
     <StdDTCs> 

      <StdDTC Action="Insert" ID="1" CK="B0011" Description="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP" /> 
      <StdDTC Action="Insert" ID="2" CK="B0012" Description="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP" /> 
      <StdDTC Action="Insert" ID="3" CK="B0013" Description="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP" /> 
      <StdDTC Action="Insert" ID="4" CK="B0014" Description="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP" /> 
      <StdDTC Action="Insert" ID="5" CK="B0015" Description="VSC_4" DTC="B0014" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP" /> 

     </StdDTCs> 
    </Cage> 
</DF> 
+0

+1 답 :-) –

0

는 :

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:rs="urn:schemas-microsoft-com:rowset" 
    xmlns:z="#RowsetSchema" 
    exclude-result-prefixes="z rs"> 

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

    <xsl:template match="/*"> 
     <DF> 
      <Cage Revision="" RevisionDate="" CPType="Authored" Ext_Identifier=""> 
       <Entities> 
        <xsl:apply-templates select="rs:data"/> 
       </Entities> 
      </Cage> 
     </DF> 
    </xsl:template> 

    <xsl:template match="rs:data"> 
     <StdDTCs> 
      <xsl:apply-templates select="z:row"/> 
     </StdDTCs> 
    </xsl:template> 

    <xsl:template match="z:row"> 
     <StdDTC action="Insert"> 
      <xsl:copy-of select="@*"/> 
     </StdDTC> 
    </xsl:template> 

</xsl:stylesheet> 

결과 트리입니다

<DF> 
    <Cage Revision="" RevisionDate="" CPType="Authored" Ext_Identifier=""> 
     <Entities> 
      <StdDTCs> 
       <StdDTC action="Insert" ID="1" CK="B0011" Description="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP" /> 
       <StdDTC action="Insert" ID="2" CK="B0012" Description="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP" /> 
       <StdDTC action="Insert" ID="3" CK="B0013" Description="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP" /> 
       <StdDTC action="Insert" ID="4" CK="B0014" Description="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP" /> 
       <StdDTC action="Insert" ID="5" CK="B0015" Description="VSC_4" DTC="B0014" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP" /> 
      </StdDTCs> 
     </Entities> 
    </Cage> 
</DF> 
+0

답장에 대해 감사드립니다. – Ramm