我有使用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一點。
<?xml version="1.0" encoding="UTF-8"?>
<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>
幫我在制定這個XSLT。
你的問題是什麼? –
ABCD應包含哪些內容? –
嗨,我無法打印所有5行。我只能打印一行。 ABCD將包含類似於StdDTC。我沒有提到那個bcoz裏面的dat,如果我可以做StdDTC,我也可以做ABCD。另外,我的XSLT是一個原始的XSLT。怎麼能更系統化。謝謝 – Ramm