File paths with XSLT includes

2019-08-15 18:52发布

I'm working on a website with a large number of pages, and each one has this in it: <xsl:include href="team-menu.xsl" />

This xsl file is stored in the root directory.

Essentially including my "team menu" on each page. My problem is when I include this on nested pages, e.g. "/teammembers/smith.xsl", the links in the menu are broken because they refer to pages that aren't in the same directory as the page i'm viewing.

This is probably really easy, but I just don't know how to fix it. Is there a way to tell the XSL the root directory and/or set some sort of global directory? Thanks for your help!

标签: html xml xslt
2条回答
放荡不羁爱自由
2楼-- · 2019-08-15 19:50

If I understand your question correctly you could just use absolute links, instead of relative ones.

I.e. /index.xml instead of index.xml.

查看更多
霸刀☆藐视天下
3楼-- · 2019-08-15 19:56

You can use XSL parameters to pass the base directory. All processors come with a mechanism for passing these (eg xsltproc --stringparam basedir style). Within your stylesheet, you should be able to use something like the following to consume the parameter:

<xsl:param name="basedir" />
<xsl:include href="{$basedir}/team-menu.xsl" />
查看更多
登录 后发表回答