================================================= = ======================== " luca milan" <卢******** @ hotmail.com>在消息中写道 news:3f ********************* @ news.frii.net ... 感谢Dimitre, 非常有用,最后的建议我需要在每个CAT标签中嵌套产品 - LISTS: < CAT ID =" 1" > < PROD ID =" 6"> < NAME> Prod。姓名< / NAME> < DESC><![CDATA [Html desc]]>< / DESC> < / PROD> <! - 依此类推...... - > < / CAT> 非常感谢任何帮助!!! ***通过Developersdex发送 http://www.developersdex.com *** Hello,have a problem with this XML, I need XSLT to filter the products listbased on rules writes in RULE tag.I need copy only CAT and PROD data in PRODUCTS-LIST that match CAT andPROD ID''s in RULE tag.for ex:================================================== ========================<ROOT><PAGE NAME="homepage" URL="HP.html"><RULES><RULE><CAT ID="1"><PRO ID="3"></PRO><PRO ID="6"></PRO></CAT><CAT ID="3"><PRO ID="2"></PRO><PRO ID="10"></PRO></CAT></RULE></RULES></PAGE><PRODUCTS-LIST><CAT ID="1"><PROD ID="12"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="6"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="3"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT><CAT ID="2"><PROD ID="7"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT><CAT ID="3"><PROD ID="10"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="1"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="2"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT></PRODUCTS-LIST></ROOT>================================================== ========================the final result of XSLT trasf.================================================== ========================<ROOT><PRODUCTS-LIST><CAT ID="1"><PROD ID="6"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="3"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT><CAT ID="3"><PROD ID="10"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="2"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT></PRODUCTS-LIST></ROOT>================================================== =======================Can anybody help me?Thanks for answers!Luca 解决方案 This transformation:<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output omit-xml-declaration="yes" indent="yes"/><xsl:strip-space elements="*"/><xsl:template match="ROOT"><xsl:copy><xsl:apply-templates select="PRODUCTS-LIST"/></xsl:copy></xsl:template><xsl:template match="PRODUCTS-LIST"><xsl:copy><xsl:apply-templatesselect="CAT[@ID = /*/*/*/RULE/CAT/@ID]"/></xsl:copy></xsl:template><xsl:template match="CAT"><xsl:copy-of select="PROD[@ID = /*/*/*/RULE/CAT[@ID = current()/@ID]/PRO/@ID]"/></xsl:template></xsl:stylesheet>when applied on your source.xml:<ROOT><PAGE NAME="homepage" URL="HP.html"><RULES><RULE><CAT ID="1"><PRO ID="3"></PRO><PRO ID="6"></PRO></CAT><CAT ID="3"><PRO ID="2"></PRO><PRO ID="10"></PRO></CAT></RULE></RULES></PAGE><PRODUCTS-LIST><CAT ID="1"><PROD ID="12"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="6"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="3"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT><CAT ID="2"><PROD ID="7"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT><CAT ID="3"><PROD ID="10"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="1"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><PROD ID="2"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD></CAT></PRODUCTS-LIST></ROOT>produces the wanted result:<ROOT><PRODUCTS-LIST><PROD ID="6"><NAME>Prod. name</NAME><DESC> Html desc </DESC></PROD><PROD ID="3"><NAME>Prod. name</NAME><DESC> Html desc </DESC></PROD><PROD ID="10"><NAME>Prod. name</NAME><DESC> Html desc </DESC></PROD><PROD ID="2"><NAME>Prod. name</NAME><DESC> Html desc </DESC></PROD></PRODUCTS-LIST></ROOT>=====Cheers,Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL"Luca" <lu********@hotmail.com> wrote in messagenews:50**************************@posting.google.c om... Hello, have a problem with this XML, I need XSLT to filter the products list based on rules writes in RULE tag. I need copy only CAT and PROD data in PRODUCTS-LIST that match CAT and PROD ID''s in RULE tag. for ex: ================================================== ======================== <ROOT> <PAGE NAME="homepage" URL="HP.html"> <RULES> <RULE> <CAT ID="1"> <PRO ID="3"></PRO> <PRO ID="6"></PRO> </CAT> <CAT ID="3"> <PRO ID="2"></PRO> <PRO ID="10"></PRO> </CAT> </RULE> </RULES> </PAGE> <PRODUCTS-LIST> <CAT ID="1"> <PROD ID="12"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="6"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="3"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> </CAT> <CAT ID="2"> <PROD ID="7"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> </CAT> <CAT ID="3"> <PROD ID="10"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="1"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="2"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> </CAT> </PRODUCTS-LIST> </ROOT> ================================================== ======================== the final result of XSLT trasf. ================================================== ======================== <ROOT> <PRODUCTS-LIST> <CAT ID="1"> <PROD ID="6"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="3"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> </CAT> <CAT ID="3"> <PROD ID="10"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <PROD ID="2"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> </CAT> </PRODUCTS-LIST> </ROOT> ================================================== ======================= Can anybody help me? Thanks for answers! LucaThanks Dimitre,very useful, last suggetstionI need nest PRODUCTS-LISTS into each CAT tag:<CAT ID="1"><PROD ID="6"><NAME>Prod. name</NAME><DESC><![CDATA[ Html desc ]]></DESC></PROD><!-- and so on.... --></CAT>Thanks a lot for any Help!!!*** Sent via Developersdex http://www.developersdex.com ***Don''t just participate in USENET...get rewarded for it!I don''t see any PRODUCTS-LISTS below??? Nor any nesting.=====Cheers,Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL"luca milan" <lu********@hotmail.com> wrote in messagenews:3f*********************@news.frii.net... Thanks Dimitre, very useful, last suggetstion I need nest PRODUCTS-LISTS into each CAT tag: <CAT ID="1"> <PROD ID="6"> <NAME>Prod. name</NAME> <DESC><![CDATA[ Html desc ]]></DESC> </PROD> <!-- and so on.... --> </CAT> Thanks a lot for any Help!!! *** Sent via Developersdex http://www.developersdex.com *** Don''t just participate in USENET...get rewarded for it! 这篇关于如何将数据从XML过滤到XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 14:26