如何有条件地在 xslt 中导入样式表? [英] How to Import stylesheets in xslt conditionally?

查看:25
本文介绍了如何有条件地在 xslt 中导入样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在检查了一些条件后导入样式表?

Is there any way to import stylesheets after checking some conditions?

比如,如果变量 $a="1" 的值则导入 1.xsl 否则导入 2.xsl.

Like,if the value of variable $a="1" then import 1.xsl or else import 2.xsl.

推荐答案

大家好,请问有什么办法导入吗检查一些后的样式表条件?

Hi All, Is there any way to import stylesheets after checking some conditions?

比如,如果变量 $a="1" 的值然后导入 1.xsl 或者导入2.xsl.

Like,if the value of variable $a="1" then import 1.xsl or else import 2.xsl.

不, 指令只是编译时.

No, the <xsl:import> directive is only compile-time.

在 XSLT 2.0 中可以使用 use-when 用于有限条件编译的属性.

In XSLT 2.0 one can use the use-when attribute for a limited conditional compilation.

例如:

<xsl:import href="module-A.xsl" 
     use-when="system-property('xsl:vendor')='vendor-A'"/>

use-when 属性的局限性在于评估该属性时没有动态上下文——特别是这意味着没有定义范围内变量.

The limitations of the use-when attribute are that there is no dynamic context when the attribute is evaluated -- in particular that means that there are no in-scope variables defined.

非 XSLT 解决方案是在调用转换之前动态更改 声明的 href 属性:

A non-XSLT solution is to dynamically change the href attribute of the <xsl:import> declaration before the transformation is invoked:

  1. 将 xsl 样式表解析为 XML 文件

  1. Parse the xsl stylesheet as an XML file

评估确定应导入哪个样式表的条件.

Evaluate the condition that determines which stylesheet should be imported.

声明的href属性的值设置为动态确定的要导入的样式表的URI.

Set the value of the href attribute of the <xsl:import> declaration to the URI of the dynamically determined stylesheet-to-be-imported.

使用刚刚修改的内存中 xsl 样式表调用转换.

Invoke the transformation with the in-memory xsl stylesheet that was just modified.

这篇关于如何有条件地在 xslt 中导入样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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