开发者

xslt include/import path

I use XSLT as template engine in my PHP framework. Some XSLT files are in different folders,so if I want to include/import xslt template not from main directory I have to type a lot:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">   
    <xsl:import href="dir1/dir2/dir3/dir4/layout.xsl"/> 

    <xsl:template name="content">
        <html>
            <head>
                <title>action.xsl</title>
            </head>
            <body>
                test
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>

Is there any easy way to redu开发者_运维知识库ce this dir1/dir2/dir3/dir4/layout.xsl ? dir1/dir2/dir3/dir4/ are static (never changes).

Separate template with all includes does not fit, because each template requires different files, and after some time it is difficult to understand what's included and where.

I thought perhaps ​​it is possible to do something with xml:base <xsl:import href="layout.xsl" xml:base="dir1/dir2/dir3/dir4/" />, but do not know how.

Thanks


<xsl:import href="layout.xsl" xml:base="dir1/dir2/dir3/dir4/" />

is possible in XSLT 2.0 but not in 1.0.

Did you try it in XSLT 2.0 (e.g. in Saxon), and if so, what was the result?

You cannot put import statements into templates; each import statement must be at the top level below the stylesheet element.


[XSLT 1.0]

You can't use for example xsl:import like this:

 <xsl:import href="$mypath"/>

because hrefevaluates always to a string. AVT is not allowed either.


One possible solution is to define a specific stylesheet in the target folder which provides all required imports (and in this stylesheet you will need simple relative paths). In this way the main xsl will need to import only that single specific stylesheet.

For instance, transformA.xsl will import ir1/dir2/dir3/dir4/transformA_imports.xsl which will import all required files such as layout.xsl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜