我有一个来自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