2013-03-11 8 views
1

Chrome과 Safari에서이 파일을 표시하려고했습니다. 기본적으로 튜토리얼에서이 두 파일을 가져 왔습니다. 그러나 그것이 모두 표시 할 때 원시 XML을 표시하고 xsl 파일을 읽지 않는 것 같습니다. 이 두 파일은 모두 같은 디렉토리에 있습니다.XSL 파일이있을 때 XML의 형식이 지정되지 않았습니다.

도움을 주시면 감사하겠습니다. 미리 감사드립니다.

<?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> 
     <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 version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="test.xsl"?> 
<catalog> 
<cd> 
    <title>Empire Burlesque</title> 
    <artist>Bob Dylan</artist> 
    <country>USA</country> 
    <company>Columbia</company> 
    <price>10.90</price> 
    <year>1985</year> 
</cd> 
</catalog> 
+1

어리석은 질문이지만 XSLT 파일 이름을 "test.xsl"(대문자 사용)이라고 했습니까? – JLRishe

+0

하하, 예, 방금 다시 확인했습니다. – jaesanx

+1

닫는''태그가 없습니다. – Joel

답변

0

스타일 시트 : test.xsl로

<?xml version="1.0" encoding="ISO-8859-1"?> 

<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns="http://www.w3.org/1999/xhtml"> 
    <xsl:output method="html"/> 

    <xsl:template match="/"> 
    <html> 
     <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> 

html로 페이지를 저장합니다 인덱스로 저장합니다. XHTML

<catalog> 
    <cd> 
    <title>Empire Burlesque</title> 
    <artist>Bob Dylan</artist> 
    <country>USA</country> 
    <company>Columbia</company> 
    <price>10.90</price> 
    <year>1985</year> 
    </cd> 
</catalog> 

장소 같은 폴더에 두 파일.

은 IE10에서 테스트되었습니다. 당신의 XSL의 기본 네임 스페이스 (xmlns)를 추가

+0

지금 작동해야합니다. 정말로); – Joel

+0

모두에게 고마워,이 고정은 나를 위해 일했다. .xhtml로 저장하면 – jaesanx

0

시도 :

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://www.w3.org/1999/xhtml"> 
    ... 
</xsl:stylesheet> 

그것은 나를 위해 IE에서이 방식으로 작동, 그것은없이 작동하지 않습니다.

+0

Firefox는 해당 네임 스페이스없이 올바르게 렌더링합니다. –

+0

@rdc 그렇습니다. Chrome은 나를 위해 어떤 것도 표시하지 않습니다. XSL 지원은 브라우저간에 매우 혼란스럽게 변하는 것 같습니다. – famousgarkin