Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xslt未从命名空间元素获取值_Xml_Xslt_Xml Namespaces - Fatal编程技术网

Xml xslt未从命名空间元素获取值

Xml xslt未从命名空间元素获取值,xml,xslt,xml-namespaces,Xml,Xslt,Xml Namespaces,我试图从命名空间为dc的元素中检索数据。除这些值外,其他一切都正常工作 以下是我的XML的缩写版本: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet href="sci.xsl" type="text/xsl" ?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss

我试图从命名空间为
dc
的元素中检索数据。除这些值外,其他一切都正常工作

以下是我的XML的缩写版本:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="sci.xsl" type="text/xsl" ?>

<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<channel>
    <title>SciTimes News</title>
    <link>home.htm</link>

    <description>SciTimes delivers up-to-the-minute news and information on the latest stories from the world of science and technology.</description>

    <dc:language>en-us</dc:language>

    <dc:date>2008-03-24T12:22:54+09:00</dc:date>

    <sy:updatePeriod>hourly</sy:updatePeriod>

    <sy:updateFrequency>1</sy:updateFrequency>

    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>


    <image>
        <title>SciTimes.com</title>
        <link>home.htm</link>
        <url>scitimes.jpg</url>
        <width>620</width>
        <height>96</height>
        <description>SciTimes delivers up-to-the-minute news and information on the latest stories from the world of  science and technology.</description>
    </image>

    <item>
        <title>Visual Memory</title>
        <link>vm.htm</link>
        <description>BOULDER, Colorado - The ability to retain memory about the details of a natural scene is unaffected by the distraction of another activity and this information is retained in "working memory" according to researchers at the University of Colorado School of Medicine. These results reinforce the notion that humans maintain useful information about previous fixations in long-term working memory rather than the limited capacity of visual short-term memory (VSTM).</description>
        <dc:pubDate>Mon, 24 Mar 2008 12:17:37 EST</dc:pubDate>
        <dc:subject>Biology</dc:subject>
    </item>
</channel>
</rss>

科学时报新闻
home.htm
《科学时报》提供最新的新闻和信息,介绍世界科技领域的最新故事。
美国英语
2008-03-24T12:22:54+09:00
每小时
1.
2000-01-01T12:00+00:00
科技时报网站
home.htm
scitimes.jpg
620
96
《科学时报》提供最新的新闻和信息,介绍世界科技领域的最新故事。
视觉记忆
vm.htm
科罗拉多BOULDER -据科罗拉多大学医学院的研究人员所说,保持对自然场景细节记忆的能力不受另一种活动的干扰,而这种信息被保留在“工作记忆”中。这些结果强化了这样一种观点,即人类在长期工作记忆中保留着关于先前固定的有用信息,而不是视觉短时记忆(VSTM)的有限容量。
美国东部时间2008年3月24日星期一12:17:37
生物
下面是我的XSL:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1"
version="1.0"
>
<!-- Start base template -->
<xsl:template match="/">
    <html>
        <head>
            <title><xsl:value-of select="rss/channel/title" /></title>
            <link rel="stylesheet" href="sci.css" />
        </head>
        <body>
                <div id="logo">
                <xsl:apply-templates select="//image"/>
            </div>
            <div id="datetime"><xsl:value-of select="//dc:date" /></div>
            <div id="links">
                <p><xsl:value-of select="//description" /></p>
                <p><img src="links.jpg" /></p>
            </div>
            <div id="news">
                <h1>RSS News Feed</h1>
                <dc:stylesheet>
                <xsl:apply-templates select="//item" /></dc:stylesheet>
            </div>
        </body>
    </html>
</xsl:template>
<!-- End base template -->

<!-- Start logo template -->
<xsl:template match="//image">
    <a href="{link}"><img src="{url}" alt="{title}" width="{width}" height="{height}" longdesc="{description}" /></a>
</xsl:template>
<!-- End Logo template -->

<!-- Start RSS item template -->
<xsl:template match="//item">
    <h2><xsl:value-of select="title" /></h2>
    <p id="subjtime"><xsl:value-of select="dc:subject" /> / <xsl:value-of select="dc:pubDate" /></p>
    <p><xsl:value-of select="description" /></p>
    <p id="itemlink">[ <a href="{link}">more</a> ]</p>
</xsl:template>
<!-- End RSS item template -->
</xsl:stylesheet>

RSS新闻源

/

[]

因此,
,以及
都不会拉入数据

我对XML完全不熟悉,所以我显然遗漏了一些东西,我只是不知道是什么。我到处寻找解决办法,但没有成功

如果有人能指出我做错了什么,我将不胜感激


谢谢

您在XSLT中的dc名称空间声明末尾缺少斜杠:

xmlns:dc="http://purl.org/dc/elements/1.1"
应该是:

xmlns:dc="http://purl.org/dc/elements/1.1/"
命名空间URI必须完全匹配。一旦解决了这个问题,XSLT应该成功地检索到您想要访问的值