2010-08-15 4 views
2

난 그냥 HTML에 XML을 변환하는 XSL을 사용하여 시작하기 그리고 난이 날에 다이빙을하기 위해 다음과 같이 도움을받을 수 호핑있어기본 XSLT 예를

다음 (A)와 같은

을 감안할 때 XML :.

<Course Title="SampleCourse"> 
    <Lesson Title="Overview"/> 
    <Section Title="Section1"> 
    <Lesson Title="S1 Lesson 1" /> 
    <Lesson Title="S1 Lesson 2" /> 
    </Section> 
    <Section Title="Sections 2"> 
    <Lesson Title="S2 Lesson 1" /> 
    </Section> 
</Course> 

또는 같은 (B) : 나는 (A)에 위의 예를 변환 수있는 XSL 파일을 생성 할 방법

<Course Title="SampleCourse"> 
    <Section Title="Section1"> 
    <Lesson Title="S1 Lesson 1" /> 
    <Lesson Title="S1 Lesson 2" /> 
    </Section> 
    <Section Title="Sections 2"> 
    <Lesson Title="S2 Lesson 1" /> 
    </Section> 
</Course> 

:

<h3>SampleCourse</h3> 
<ul> 
    <li>Overview</li> 
    <li>Section1</li> 
    <ul> 
    <li>S1 Lesson 1</li> 
    <li>S1 Lesson 2</li> 
    </ul> 
    <li>Sections 2</li> 
    <ul> 
    <li>S1 Lesson 1</li> 
    </ul> 
</ul> 

또는 (B) :

<h3>SampleCourse</h3> 
<ul> 
    <li>Section1</li> 
    <ul> 
    <li>S1 Lesson 1</li> 
    <li>S1 Lesson 2</li> 
    </ul> 
    <li>Sections 2</li> 
    <ul> 
    <li>S1 Lesson 1</li> 
    </ul> 
</ul> 

감사합니다!

답변

5
<xsl:template match="Course"> <!-- We use template to define what shows up when we encounter the element "Course" --> 
    <h3><xsl:value-of select="@Title"/></h3> <!-- value-of is used here to grab the title. @ is for attribute. --> 
    <ul> 
     <xsl:apply-templates/> <!-- apply-templates continues parsing down the tree, looking for more template matches. --> 
    </ul> 
</xsl:template> 

<xsl:template match="Section"> 
    <li><xsl:value-of select="@Title"/></li> 
    <ul> 
     <xsl:apply-templates/> 
    </ul> 
</xsl:template> 

<xsl:template match="Lesson"> 
    <li><xsl:value-of select="@Title"/></li> 
</xsl:template> 
+2

감사합니다. (자신과 같은 컷앤 파스터에 대한 작은 노트 하나 @title은 위의 예와 함께 @ 제목이어야합니다) – Evan

+0

아, 그래; 편집 됨. :) – andyvn22

+0

+1 좋은 답변입니다! –