2012-08-28 115 views
0

我想使用xslt從給定的xml文件中刪除元數據和模式信息,以便我可以在sql表中導入這些數據,但我無法從xml文件中刪除它的元數據和模式信息。 我過去三天確實做了很多Google,但我無法執行它。請爲我提供一個有效的xslt文件代碼,用於從給定的xml文件中刪除元數據和模式。使用xslt文件轉換xml數據

在這裏,我爲您提供了xml文件的代碼。

<?xml version="1.0" encoding="utf-16"?> 
<DataSet> 
    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> 
     <xs:complexType> 
     <xs:choice minOccurs="0" maxOccurs="unbounded"> 
      <xs:element name="Table"> 
      <xs:complexType> 
       <xs:sequence> 
       <xs:element name="lukas_id_nagrody" type="xs:string" minOccurs="0" /> 
       <xs:element name="ilosc" type="xs:int" minOccurs="0" /> 
       </xs:sequence> 
      </xs:complexType> 
      </xs:element> 
     </xs:choice> 
     </xs:complexType> 
    </xs:element> 
    </xs:schema> 
    <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
    <NewDataSet> 
     <Table diffgr:id="Table1" msdata:rowOrder="0"> 
     <lukas_id_nagrody>10</lukas_id_nagrody> 
     <ilosc>4</ilosc> 
     </Table> 
     <Table diffgr:id="Table2" msdata:rowOrder="1"> 
     <lukas_id_nagrody>12</lukas_id_nagrody> 
     <ilosc>10</ilosc> 
     </Table> 
     <Table diffgr:id="Table3" msdata:rowOrder="2"> 
     <lukas_id_nagrody>21</lukas_id_nagrody> 
     <ilosc>32</ilosc> 
     </Table> 
     <Table diffgr:id="Table4" msdata:rowOrder="3"> 
     <lukas_id_nagrody>32</lukas_id_nagrody> 
     <ilosc>13</ilosc> 
     </Table> 
     <Table diffgr:id="Table5" msdata:rowOrder="4"> 
     <lukas_id_nagrody>33</lukas_id_nagrody> 
     <ilosc>15</ilosc> 
     </Table> 
     <Table diffgr:id="Table6" msdata:rowOrder="5"> 
     <lukas_id_nagrody>34</lukas_id_nagrody> 
     <ilosc>2</ilosc> 
     </Table> 
    </NewDataSet> 
    </diffgr:diffgram> 
</DataSet> 

我在SSIS中使用xml任務。

轉換上面的XML數據後,我想要下面的輸出。

<NewDataSet> 
    <Table> 
      <lukas_id_nagrody>34</lukas_id_nagrody> 
      <ilosc>2</ilosc> 
    </Table> 
</NewDataSet> 

我想輸出這樣的東西。 謝謝。

+0

你不提,你的XML部分被認爲是元數據。 – Utkanos

+0

我編輯了我的問題並更新了我想要的示例xml輸出。 – Awadhendra

回答

1

您需要一個簡化的身份/複製模式,從NewDataSet開始並省略屬性。試試這個:

<xsl:template match="DataSet/diffgr:diffgram/NewDataSet|DataSet/diffgr:diffgram/NewDataSet//*|text()"> 
    <xsl:copy> 
     <xsl:apply-templates select='*|text()' /> 
    </xsl:copy> 
</xsl:template> 

Runnable demo(見輸出

+0

該選項正在工作,但不會複製標籤內的數據。 – Awadhendra

+0

對不起 - 對我來說很傻。固定。 – Utkanos

+0

謝謝,最後由於你的幫助,我的SSIS處於工作模式。 – Awadhendra