我有一個來自ICECAT的大XML文件。我只想要一些信息。它在這個問題filter-dynamically-xml-child-element-with-xslt-with-ssis使用XSLT構建XML文件以篩選多個子節點
現在我已經像這樣的categoriesList XML文件的以下:
<ICECAT-interface>
<Response Date="Tue Jul 25 16:00:10 2017" ID="29306604" Request_ID="1500991209" Status="1">
<CategoriesList>
<Category ID="2597" LowPic="http://images.icecat.biz/img/low_pic/2597-5095.jpg" Score="471102" Searchable="0" ThumbPic="http://images.icecat.biz/thumbs/CAT2597.jpg" UNCATID="43223323" Visible="0">
<Name ID="1088701" Value="fiber optic adapters" langid="1"/>
<Name ID="1595015" Value="glasvezeladapters" langid="2"/>
<Name ID="1088703" Value="adaptateurs de fibres optiques" langid="3"/>
<Name ID="1245208" Value="LWL-Steckverbinder" langid="4"/>
<Name ID="1088705" Value="adattatori di fibra ottica" langid="5"/>
<Name ID="1125574" Value="adaptadores de fibra óptica" langid="6"/>
<Name ID="1147616" Value="lyslederadapter" langid="7"/>
<ParentCategory ID="242">
<Names>
<Name ID="485" langid="1">networking</Name>
<Name ID="471244" langid="2">netwerken</Name>
<Name ID="343986" langid="3">réseaux</Name>
<Name ID="436999" langid="4">Netzwerke</Name>
<Name ID="1051724" langid="5">reti</Name>
<Name ID="1041258" langid="6">redes</Name>
<Name ID="34261" langid="7">netværk</Name>
<Name ID="530435" langid="8">сети/коммуникации</Name>
</Names>
</ParentCategory>
</Category>
<Category ID="4601" LowPic="http://images.icecat.biz/img/low_pic/4601-990.jpg" Score="12621" Searchable="0" ThumbPic="http://images.icecat.biz/thumbs/CAT4601.jpg" UNCATID="56101688" Visible="0">
我需要一些屬性,像ID
,LowPic
......一些Name
節點和ID
從Category
節點ParentCategory
節點。
我嘗試這樣做XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/ICECAT-interface">
<xsl:apply-templates select="Response"/>
</xsl:template>
<xsl:template match="Response">
<xsl:apply-templates select="CategoriesList"/>
</xsl:template>
<xsl:template match="CategoriesList">
<xsl:copy>
<xsl:apply-templates select="Category"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Category">
<xsl:apply-templates select="Name"/>
</xsl:template>
<xsl:template match="Name[@langid=1 or @langid=3]">
<Category>
<xsl:copy-of select="../@ID|../@LowPic|../@ThumbPic|../@UNCATID||@langid|@Value" />
</Category>
</xsl:template>
</xsl:stylesheet>
我不知道這是否是更好的方法,我沒有ParentCategory
節點的ID
。
UPDATE 對不起,我忘了,結果我想要的東西
<?xml version="1.0" encoding="utf-8"?>
<Categories>
<Category ID="2597" LowPic="http://images.icecat.biz/img/low_pic/2597-5095.jpg" ThumbPic="http://images.icecat.biz/thumbs/CAT2597.jpg" UNCATID="43223323" name="fiber optic adapters" langid="1" ParentCategory="242"/>
<Category ID="2597" LowPic="http://images.icecat.biz/img/low_pic/2597-5095.jpg" ThumbPic="http://images.icecat.biz/thumbs/CAT2597.jpg" UNCATID="43223323" name="adaptateurs de fibres optiques" langid="3" ParentCategory="242"/>
....
更新2 我修改XSLT文件我反我的過濾器位置。現在,我的貨物記錄,parentcategory ID的只是湖
如何將所需輸出樣子簡化
Name
模板? – zx485您能確保您的輸出與您的輸入完全一致嗎?您當前的預期輸出引用不在您輸入內容的文字「其他手機」。如果你的輸入XML格式良好,它也會有所幫助。目前它缺少一些結束標籤。謝謝! –
我這樣做。我改變第一篇文章中的例子 – YannickIngenierie