2016-06-07 3 views
0

2 개의 파일 xml과 xsl이 있습니다. xslt를 사용하여 xml 데이터를 가져 와서 html 테이블로 변환하고 싶습니다. 아래의 코드는 Chrome에서 작동하지 않으며 왜 xslt를 적절하게 사용하는 방법에 대한 조언이나 xslt 대신 사용할 수있는 방법에 대한 조언이 확실하지 않습니다.xslt는 xml을 html로 변환합니다.

test.xml의

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="style.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> 
    <cd> 
     <title>Hide your heart</title> 
     <artist>Bonnie Tyler</artist> 
     <country>UK</country> 
     <company>CBS Records</company> 
     <price>9.90</price> 
     <year>1988</year> 
    </cd> 
    <cd> 
     <title>Greatest Hits</title> 
     <artist>Dolly Parton</artist> 
     <country>USA</country> 
     <company>RCA</company> 
     <price>9.90</price> 
     <year>1982</year> 
    </cd> 
</catalog>` 

style.xsl

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 
    <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>` 

답변

1

한 가지를 들어, XSLT는 xsl:template 명령의 여는 태그가 없습니다 :

<xsl:template match="/"> 

또 다른 문제는 Chrome에서 로컬로 XSLT를 실행하는 데 고유 한 문제입니다 (https://stackoverflow.com/a/3839054/3016153 및 기타 참조).

+0

Bummer ... XSLT를 사용하지 않고 동일한 작업을 수행하는 방법에 대한 권장 사항은 무엇입니까? –

+0

필자는 필적 할만한 도구를 찾지 못할 것이라고 생각합니다. 스타일 시트 제공을 시도해보십시오. 또는 여기에 설명 된대로 브라우저를 설정하십시오. http://stackoverflow.com/q/18586921/3016153 –

+0

쿨 ... 고마워! –

1

서버 측에서 XSLT를 사용하고 HTML 콘텐츠를 직접 제공 할 수 있으므로 브라우저에 대해 걱정할 필요가 없습니다.

나는 이미 자바로 만들었지 만 다른 언어로도 XSLT 엔진을 가지고 있다고 확신한다.