对xsl:result文档文件名使用generate-id()并链接到HTML



我正在使用xslt将一个大的xml转换为更小的互连html文件。generate-id()函数有问题,因为生成的id与html href="和文件名中的id不一样

我通过xsl:result-document:创建了以下文件

index.html | d1e83523.html|d1e83524.html|d1e 83525.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示例(注意:后面有多个类似的结构元素)

<lab>
    <description>
        <chapter>
            <heading>Example</heading
            <operation>other elements</operation>
            <operation>other elements</operation>
            ...
        </chapter>
        ...
    </description>
</lab>

我感谢你的每一次帮助!

编辑:我正在使用generate-id()为

的许多文件获取一个唯一的文件名

如果将<xsl:for-each select="chapter/heading">更改为<xsl:for-each select="chapter/*[not(self::heading)]">,则索引生成将处理与生成结果文档相同的元素,并且生成的id应该匹配。但是,您需要在同一转换中运行两个XSLT片段,以确保获得相同的id,如果您有单独的样式表,则不能保证生成id会得到相同的结果。

最新更新