【发布时间】:2014-05-12 14:22:28
【问题描述】:
我正在尝试从 XML 进行 XSLT 转换,我想转换书籍内容,我有这样的 XML 文件,我需要使用 XSLT 对其进行转换。我知道为每个部分创建模板很热门,但我只有基本的 XSLT 经验,所以我不知道如何应用它。
<book>
<section id="1">
<name>Heading First chapter</name>
<p><i/> some text </p>
<p> other text </p>
<subsection id="1.1">
<name>Heading second chapter</name>
<subsubsection id="1.1.1">
<name>Heading third chapter</name>
<p>some text</p>
</subsubsection>
</subsection>
</section>
</book>
我想要的是这样的 HTML:
<div>
<h1>1 Heading First chapter</h1>
<p><i>some text</i>
<p>other text</p>
<div>
<h2>1.1 Heading second chapter</h2>
<div>
<h3>1.1.1 Heading third chapter</h3>
<p>some text</p>
</div>
</div>
</div>
我的尝试:
<xsl:template match="/">
<body>
<xsl:for-each select="book">
<xsl:apply-templates select="."></xsl:apply-templates>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="p[i]">
<p>
<em>
<xsl:value-of select="."/>
</em>
</p>
</xsl:template>
<xsl:template match="section/name">
<p>
<h2>
<xsl:value-of select="."/>
</a>
</h2>
</p>
</xsl:template>
你知道如何进行转换吗?
【问题讨论】:
-
你试过什么没用?
标签: html xml xslt transformation