0

の名前空間を持つ要素からデータを取得しようとしています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>

そして、ここに私の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>

したがって、<xsl:value-of select="//dc:date" />とはデータを取り込みません<xsl:value-of select="dc:subject" /><xsl:value-of select="dc:pubDate" />

私は XML にまったく慣れていないので、明らかに何かが欠けています。何がわからないのですか。解決策を探して検索しましたが、成功しませんでした。

誰かが私が間違っていることを指摘できれば、それは大歓迎です。

ありがとう

4

1 に答える 1

1

XSLT の dc 名前空間宣言の末尾にスラッシュがありません:

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

次のようにする必要があります。

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

名前空間 URI は正確に一致する必要があります。それが修正されると、XSLT はアクセスしたい値を正常に取得するはずです。

于 2013-04-23T19:46:23.740 に答える