以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  3个xml文档成功合并了2个,最后一个文档为什么没读出来[求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=60845)


--  作者:fangel2000
--  发布时间:4/3/2008 11:27:00 AM

--  3个xml文档成功合并了2个,最后一个文档为什么没读出来[求助]
第一个xml文档:1.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml:stylesheet type="text/xsl" href="3.xsl"?>
<rss version="2.0">
    <channel>
        <item>
            <title> Nikon Coolpix S600 </title>
            <category> Digital Cameras </category>
        </item>

        <item>
            <title> Griffin TuneBuds </title>
            <category> Headphones </category>
        </item>
    </channel>
</rss>

第二个XML文档:2.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
    <channel>
         <item>
            <title> Lawn Aerator Sandals </title>
            <category> Garden </category>
        </item>

        <item>
            <title> Belkin Laptop Hideaway </title>
            <category> Notebook Accessories </category>
        </item>
    </channel>
</rss>

第三个xml文档:3.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
    <channel>
        <item>
            <title>22222</title>
            <category>11111</category>
        </item>

        <item>
            <title>3333333</title>
            <category>444444</category>
        </item>
    </channel>

</rss>

我写了这样的一个合并文件:merge.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<xml>
 <file>2.xml</file>
 <file>3.xml</file>
</xml>


然后xsl文件:3.xsl
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="gb2312" indent="yes" />
<xsl:variable name="temp" select="document('merge.xml')//file" />

<xsl:template match="/">
<html>
  <head></head>
  <body>
   <table border="1">
    <xsl:apply-templates select="//item" />
    <xsl:call-template name="temp3"/>
   </table>
  </body>
</html>
</xsl:template>


<xsl:template match="item">
<tr>
  <td><xsl:value-of select="title" /></td>
  <td><xsl:value-of select="category" /></td>
</tr>
</xsl:template>

<xsl:template name="temp3">
 <xsl:variable name="temp2" select="document($temp)//item"/>
 <xsl:for-each select="$temp2">
  <tr bgcolor="#FF0000">
   <td><xsl:value-of select="title" /></td>      
   <td><xsl:value-of select="category" /></td>
  </tr>
 </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

这样以后运行1.xml
得出结果:
Nikon Coolpix S600           Digital Cameras
Griffin TuneBuds              Headphones/Headsets
Lawn Aerator Sandals       Garden
Belkin Laptop Hideaway    Notebook Accessories

成功合并了两个,为什么第三个xml文档没有合并上去?3.xsl那个地方出错了?


--  作者:Qr
--  发布时间:4/3/2008 2:18:00 PM

--  
http://blogger.org.cn/blog/more.asp?name=Qr&id=33439
--  作者:fangel2000
--  发布时间:4/3/2008 5:08:00 PM

--  
呵呵,改正了一下。成功了。Thank you!
刚看XSL,所以代码写的是在有点难度,都不知道document(.)。呵呵,琢磨了好久
这下论文的这个片段终于有写头了
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms