【发布时间】:2015-12-05 19:44:53
【问题描述】:
我正在使用 xslt 将一个大的 xml 转换为更小的相互链接的 html 文件。我在使用 generate-id() 函数时遇到了麻烦,因为生成的 id 与 html href="" 和文件名中的 id 不同
我通过 xsl:result-document 创建以下文件:
index.html | d1e83523.html | d1e83524.html | d1e83525.html | ...
index.html 应该包含一个链接到其他 *.html 文件的列表
index.html 我想要,但我得到的只是不同的 id:
<ul>
<li><a href="d1e83523.html">Sample 1</a></li>
<li><a href="d1e83524.html">Sample 2</a></li>
<li><a href="d1e83525.html">Sample 3</a></li>
</ul>
xsl 创建 index.html:
<xsl:template match="lab/*">
<xsl:result-document encoding="utf-8" method="html" href="HTML_out/index.html" >
<html>
<head></head>
<body>
<ul>
<xsl:for-each select="chapter/heading">
<li>
<a href="{generate-id()}.html">
<xsl:value-of select="foo"/>
</a>
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:result-document>
</xsl:template>
xsl 创建其他 *.html:
<xsl:template match="chapter/*[not(self::heading)]">
<xsl:for-each select=".">
<xsl:result-document encoding="utf-8" method="html" href="HTML_out/{concat(generate-id(), '.html')}" >
<html>
<head></head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
xml-sample(注意:后面有多个描述类结构元素)
<lab>
<description>
<chapter>
<heading>Example</heading
<operation>other elements</operation>
<operation>other elements</operation>
...
</chapter>
...
</description>
</lab>
感谢您的每一次帮助!
编辑:我正在使用 generate-id() 为这些文件获取唯一的文件名
【问题讨论】:
标签: html xml xslt xslt-1.0 saxon