1

この奇妙な問題が発生しました。XSLがxmlで機能していません。これは私のxmlおよびxslコードです。

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xsl-stylesheet type= "text/xsl" href= "w3c.xsl"?>
<catalog>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
    <cd>
        <title>Eros</title>
        <artist>Eros Ramazzotti</artist>
        <country>EU</country>
        <company>BMG</company>
        <price>9.90</price>
        <year>1997</year>
    </cd>
    <cd>
        <title>Romanza</title>
        <artist>Andrea Bocelli</artist>
        <country>EU</country>
        <company>Polydor</company>
        <price>10.80</price>
        <year>1996</year>
    </cd>
</catalog>

これは私のxslです:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

ノート:

私はこのコードをW3Cから取得したので、機能しています。グーグルで検索しましたが、機能するソリューションが見つかりませんでした。FirefoxとChromeを使用しましたが、いずれも機能しません。テストしました。リモートサーバーも機能しません。「このXMLファイルにはスタイル情報が関連付けられていないようです。ドキュメントツリーを以下に示します。」というエラーが表示されます。同じエラーが発生します。フルパスからファイル名だけへの可能なリンク。また、-allow-file-access-from-filesを使用してchromeを試しましたが、機能しません。これを修正するのを手伝ってください。

4

2 に答える 2

3

XML ファイルの 2 行目に次のように記載されていることに注意してください。

<?xsl-stylesheet type= "text/xsl" href= "w3c.xls"?>

w3c.xls ( xsl ではなく ?) に注意してください。ファイル名は何ですか? であることに注意してxml-stylesheetくださいxsl-stylesheet

したがって、これでうまくいくはずです:

<?xml-stylesheet type= "text/xsl" href= "w3c.xsl"?>
于 2012-08-28T13:42:14.610 に答える
0

この問題を再現できません

提供された XSLT スタイルシートの場合:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

提供された XML ドキュメントに (私が利用できる 9 つの異なる XSLT プロセッサすべてを使用して) 適用されます。

<catalog>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
    <cd>
        <title>Eros</title>
        <artist>Eros Ramazzotti</artist>
        <country>EU</country>
        <company>BMG</company>
        <price>9.90</price>
        <year>1997</year>
    </cd>
    <cd>
        <title>Romanza</title>
        <artist>Andrea Bocelli</artist>
        <country>EU</country>
        <company>Polydor</company>
        <price>10.80</price>
        <year>1996</year>
    </cd>
</catalog>

正しい結果が生成されます。

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <tr>
                <td>Greatest Hits</td>
                <td>Dolly Parton</td>
            </tr>
            <tr>
                <td>Eros</td>
                <td>Eros Ramazzotti</td>
            </tr>
            <tr>
                <td>Romanza</td>
                <td>Andrea Bocelli</td>
            </tr>
        </table>
    </body>
</html>
于 2012-08-28T13:55:01.130 に答える