XSLT 文档功能 - 文件夹层次结构 [英] XSLT Document Function - Folder Hierarchy

查看:28
本文介绍了XSLT 文档功能 - 文件夹层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xslt 1.0 并尝试使用 XSLT 文档功能将样式表应用于文件夹层次结构.文件夹结构如下,但我似乎无法在网上找到任何关于如何执行此操作的可靠参考.

I am working with xslt 1.0 and trying to use the XSLT document function to apply the stylesheet to a hierarchy of folders. The folder structures is as below, but I cannot seem to find any reliable references on the Web on how to do this.

a/
└── b
    └── c
        ├── d
        ├── e
        ├── f

有没有一种方法可以通过文件夹 a 中的文件(a 具有指向文件夹层次结构中的文件名的链接)将样式表应用到节点、文件中、文件夹 f 中的节点.

Is there a way I can apply my stylesheet to nodes, in a file, in folder f via a file in folder a (a has links to file names in folder hierarchy).

更新 #2

book01.xml
<?xml version="1.0" encoding="utf-8" ?>
<book location="../collection/book01.xml">
    <chapter>chapter001</chapteer>
</book>

chapter01.xml
<?xml version="1.0" encoding="utf-8" ?>
<chapter location="../collection/book01/chapter01.xml">
    <page>page01</page>
</chapter>

page01.xml
<?xml version="1.0" encoding="utf-8" ?>
<page location="../collection/book01/chapter01/page01.xml">
    <pagenumber>page 1</pagenumber>
    <text>
      page one.
    </text>
</page>

Output

Book Name: Book XX
  Chapter XX
    Page XX
      page xx.

推荐答案

我不确定这是在您的用例上下文中实现您想要实现的目标的可行/合理的方法;但是,您可以保留最初的计划,即使用 xsl:for-eachdocument().

I'm not sure this is a feasable/reasonable way to implement what you want achieve in the context of your use case; however, you can stay with you initial plan, that is working with xsl:for-each and document().

例如,假设您有包含路径列表的输入文件:

For example, assume you have the input file with the list of paths:

<files>
    <file>book001.xml</file>
    <file>chapter001.xml</file>
</files>

可以合理地使用此输入来定义包含所有输入文档的变量并应用模板:

This input can be reasonably used to define a variable containing all your input documents and apply templates:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    version="1.0">

    <xsl:template match="files">
        <xsl:variable name="docs">
            <docs>
                <xsl:for-each select="file">
                    <xsl:copy-of select="document(.)"/>
                </xsl:for-each>
            </docs>
        </xsl:variable>

        <xsl:apply-templates select="msxsl:node-set($docs)"/>
    </xsl:template>

    <!-- now you can match elements of your xml files -->

</xsl:stylesheet>

请注意,我需要扩展函数来评估节点集.这在 xsltproc 中明确可用,或者您也可以从 EXSLT 获得它.

Notice that I needed the extension function in order to evaluate to a node-set. This is definetly available in xsltproc, or you can get it from EXSLT anyway.

在示例中,我假设输入文件位于 book001.xml 和chapter001.xml 文件的同一文件夹中.

In the example I've assumed that the input file is in the same folder of the book001.xml and chapter001.xml file.

这篇关于XSLT 文档功能 - 文件夹层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆