Say I have XMLise the book The Complete Reference - Java. Now instead of writing the contents of the book, I (rather everybody) would like to generate it from the tags. So..
说我有XMLise的书The Complete Reference - Java。现在,我(而不是每个人)都想从标签中生成它,而不是写书的内容。所以..
Following is the XML structure -
以下是XML结构 -
<Books>
<Book>
<Part n="1" h="The Java Language">
<SubHead h="Basics">
<Topic n="1" h="The History and Evolution of Java">
.....
</Topic>
<Topic n="2" h="An overview of Java">
.....
</Topic>
<Topic n="3" h="Data Types, Variables, and Arrays">
.....
</Topic>
</SubHead>
<SubHead h="Intermediate">
<Topic n="4" h="Operators">
.....
</Topic>
<Topic n="5" h="Control Statements">
.....
</Topic>
<Topic n="6" h="Looping">
.....
</Topic>
</SubHead>
</Part>
<Part n="2" h="OOPS">
<SubHead h="Basics">
<Topic n="7" h="Introduction to Classes">
.....
</Topic>
<Topic n="8" h="Inheritance">
.....
</Topic>
</SubHead>
<SubHead h="Intermediate">
<Topic n="8" h="Packages and Interfaces">
.....
</Topic>
<Topic n="9" h="Exception Handling">
.....
</Topic>
</SubHead>
</Part>
</Book>
</Books>
The dotted lines means the content of the book. Now How to get the following output in HTML, along with the detailed description of the contents of the Topic Tag. I mean to say that, I am looking for the Content section of any book.
虚线表示书的内容。现在如何在HTML中获得以下输出,以及主题标记内容的详细说明。我的意思是说,我正在寻找任何书籍的内容部分。
Part 1 - The Java Language
Basics
1. The History and Evolution of Java
2. An overview of Java
3. Data Types, Variable, and Arrays
Intermediate
4. Operators
5. Control Statements
6. Looping
Part 2 - OOPS
Basics
7. Introduction to Classes
8. Inheritance
Intermediate
9. Packages and Interfaces
10. Exception Handling
1 个解决方案
#1
1
Following Xsl gives you an output data you're asking:
以下Xsl为您提供了一个输出数据:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="Book" >
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Part" >
Part <xsl:value-of select="@n"/> - <xsl:value-of select="@h"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="SubHead">
<xsl:value-of select="@h"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Topic" >
<xsl:value-of select="@n"/>. <xsl:value-of select="@h"/>
</xsl:template>
</xsl:stylesheet>
The output will be:
输出将是:
Part 1 - The Java Language
Basics
1. The History and Evolution of Java
2. An overview of Java
3. Data Types, Variables, and Arrays
Intermediate
4. Operators
5. Control Statements
6. Looping
Part 2 - OOPS
Basics
7. Introduction to Classes
8. Inheritance
Intermediate
8. Packages and Interfaces
9. Exception Handling
#1
1
Following Xsl gives you an output data you're asking:
以下Xsl为您提供了一个输出数据:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="Book" >
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Part" >
Part <xsl:value-of select="@n"/> - <xsl:value-of select="@h"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="SubHead">
<xsl:value-of select="@h"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Topic" >
<xsl:value-of select="@n"/>. <xsl:value-of select="@h"/>
</xsl:template>
</xsl:stylesheet>
The output will be:
输出将是:
Part 1 - The Java Language
Basics
1. The History and Evolution of Java
2. An overview of Java
3. Data Types, Variables, and Arrays
Intermediate
4. Operators
5. Control Statements
6. Looping
Part 2 - OOPS
Basics
7. Introduction to Classes
8. Inheritance
Intermediate
8. Packages and Interfaces
9. Exception Handling