2011-08-16 5 views
3

일부 프로그램의 구성 정보가 들어있는 XML 파일이 있습니다.XML을 HTML 테이블로 표시하는 방법

<master> 
    <childCat1> 
    <param1>test1</param1> 
    <param2>test2</param2> 
    </childCat1> 
    <childCat2> 
    <item1>test3</item1> 
    <item2>test4</item2> 
    </childCat2> 
</master>* 

가 나는 HTML 테이블과 XML을 표시 할 XSL 스타일 시트를 만들려면 : 파일이 같이 보입니다. XSL을 사용하여 XML을 테이블로 변환하는 방법을 제안 할 수 있습니까? 매번 스타일 시트를 다시 보지 않아도 카테고리와 매개 변수를 추가 할 수 있어야합니다. 스타일 시트가 XML이 항상 카테고리, 매개 변수 및 값을 가지지 만 각 항목의 수를 가정하지는 않는다는 것을 이해하면 좋을 것입니다.

표에서 3 열을 원합니다. 나뿐만 표시 할 열을 싶습니다

Category Parameter Value 
-------------------------------- 
childCat1 param1  test1 
childCat1 param2  test2 
-------------------------------- 
childcat2 item1  item1 
childcat2 item2  item2 

등 이 나타나는 범주 사이의 구분선에 대한 갖도록 좋을 것이다 그러나 나는 그들없이 살 수 있습니다.

미리 도움을 청하십시오. 다른 모든 실패하면이 작업을 수행하는 PHP 코드를 작성하지만 XSL 스타일 시트 훨씬 더 다재 다능 한 것입니다.

설명 :

내 취향은 사전에 단 한 가지를 알고 XSL입니다 -는 XML 요소, 카테고리와 그 직계 자녀의 두 가지 수준이 있는지 확인합니다. 그래서 내가 추가 (또는 삭제) - 추가 범주 또는 하위 또는 무엇이든 상관없이 xsl은 수동 업데이트없이 작동합니다.

답변

0

나는 이것이 당신이

<?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="/master"> 
<html><body> 
<table border="1"> 
    <tr bgcolor="yellow"> 
     <th style="text-align:left">Category</th> 
     <th style="text-align:left">Parameter</th> 
     <th style="text-align:left">Value</th> 
     </tr> 
    <xsl:apply-templates select="./*" mode='category' /> 

</table> 
</body></html> 
</xsl:template> 

<xsl:template match='*' mode='category'> 
<tr><td colspan='3'></td></tr> 
<xsl:apply-templates select="./*" mode='parameter' /> 
</xsl:template> 

<xsl:template match='*' mode='parameter'> 
<tr> 
<td><xsl:value-of select="name(..)"/></td> 
<td><xsl:value-of select="name()"/></td> 
<td><xsl:value-of select="."/></td> 
</tr> 

</xsl:template> 
</xsl:stylesheet> 
찾고있는 것을 생각
관련 문제