我一直在努力让两个(或更多)
XML文件由同一个xsl文件处理.
我按照这篇文章中的步骤操作:Including an XML file in an XML/XSL file但我无法使其工作.
这是第一个xm文件 – Dial_Stats_MWB:
<?xml version="1.0" encoding="utf-8"?> <UK_Products_Pipeline> <LastFinishCode> <SiteName>UK</SiteName> <LastFinishCode>Agent logout</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> <LastFinishCode> <SiteName>UK</SiteName> <LastFinishCode>Busy</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> <LastFinishCode> <SiteName>UK</SiteName> <LastFinishCode>BW Sale</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> </UK_Products_Pipeline>
第二个文件 – Dial_Stats_UK:
<?xml version="1.0" encoding="utf-8"?> <UK_Products_Pipeline> <LastFinishCode> <SiteName>MWB</SiteName> <LastFinishCode>Bearer Capability Not Presently Authorized (ISDN Cause Code 57)</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> <LastFinishCode> <SiteName>MWB</SiteName> <LastFinishCode>Confirmed Booking</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> <LastFinishCode> <SiteName>MWB</SiteName> <LastFinishCode>Lost</LastFinishCode> <Numbers>1</Numbers> </LastFinishCode> </UK_Products_Pipeline>
和XSL文件:
<?xml version="1.0" encoding='utf-8'?> <xsl:stylesheet xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title> XSLT with XML included </title> </head> <body style="background-color:lightblue;color:green"> <table cellSpacing="0" border="1" cellPadding="2"> <!-- Set Variables --> <xsl:variable name="external"> <xsl:copy-of select="document('D:\DATA\Marquee\dial_stats_UK.xml')/*"/> </xsl:variable> <!-- Process Data Start --> <xsl:for-each select="//UK_Products_Pipeline/LastFinishCode"> <tr> <xsl:if test="SiteName ='MWB'"> <td> <xsl:value-of select="SiteName"/> </td> <td> <xsl:value-of select="LastFinishCode"/> </td> <td> <xsl:value-of select="Numbers"/> </td> </xsl:if> </tr> </xsl:for-each> <!-- Process File Data Start --> <xsl:call-template name="ExternalData"> <xsl:with-param name="data" select="$external"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name="ExternalData"> <xsl:param name="data"/> <xsl:variable name="external"> <xsl:copy-of select="document('D:\DATA\Marquee\dial_stats_UK.xml')/*"/> </xsl:variable> <table cellSpacing="0" border="1" cellPadding="2" style="background-color:white;color:black"> <tr> <td> I do see this. </td> </tr> <!-- Process External Data --> <xsl:for-each select="//UK_Products_Pipeline/LastFinishCode"> <tr> <td> <xsl:value-of select="SiteName"/> </td> </tr> <tr> <xsl:if test="SiteName ='UK'"> <td> <xsl:value-of select="SiteName"/> </td> <td> <xsl:value-of select="LastFinishCode"/> </td> <td> <xsl:value-of select="Numbers"/> </td> </xsl:if> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
我不知道你能不能就我在这里做错了什么给我任何建议?
更改
原文链接:/xml/292693.html`<xsl:for-each select="//UK_Products_Pipeline/LastFinishCode">`
至
`<xsl:for-each select="document('file:///D:/DATA/Marquee/dial_stats_UK.xml')/UK_Products_Pipeline/LastFinishCode">`
在模板中,您要处理来自第二个输入文件的数据.
虽然更简洁的方法是使用您想要处理的第二个文件中的节点的模式编写匹配模板.
然后你会做:
`<xsl:apply-templates select="document('file:///D:/DATA/Marquee/dial_stats_UK.xml')/UK_Products_Pipeline" mode="my-mode"/>`
并且您的该模式的模板将输出您想要的表.