XSLT条件包括外部文件

时间:2021-06-16 09:50:51

I want to perform a conditional include in XSLT, but xsl:include is a top level element. You can only use xsl:if or xsl:choose inside of a template. Is there any kind of hack or work around which allows a conditional include of an external file? I tried to use the document() function, but it fails to load my external file ( probably because it doesn't conform to some set of rules which would make it "valid" ).

我想在XSLT中执行条件包含,但xsl:include是一个*元素。您只能使用xsl:if或xsl:在模板内部选择。是否有任何类型的黑客或工作允许条件包含外部文件?我试图使用document()函数,但它无法加载我的外部文件(可能是因为它不符合某些规则使其“有效”)。

My external xml file is a bunch of xslt code fragments. depending on the value of a variable in the main XSLT file, the corisponding code from the external file should be "copy/pasted" in place ( like conditional include in C or PHP ).

我的外部xml文件是一堆xslt代码片段。根据主XSLT文件中变量的值,外部文件中的相应代码应该“复制/粘贴”到位(如C或PHP中的条件包含)。

The flow of my main XSLT file should proceed in the following manner:

我的主XSLT文件的流程应按以下方式进行:

$configurationMode
if ( $configurationMode = Standard ) { xsl:include="standard.xml" } else { xsl:include="alt.xml" }

Obviously I cannot do it as simply as the above, hence why I am asking if there is a hack or workaround.

显然我不能像上面那样简单地做到这一点,因此我在问为什么会有黑客攻击或解决方法。

8 个解决方案

#1


6  

This cannot be done with XSLT 1.0 and can be done (to a very limited extent) in XSLT 2.0 using the use-when attribute.

这不能用XSLT 1.0完成,并且可以使用use-when属性在XSLT 2.0中完成(在非常有限的范围内)。

There exist non-xslt ways of achieving the wanted dynamic altering of an xsl:include or an xsl:import directive.

存在非xslt方法来实现xsl:include或xsl:import指令的所需动态更改。

One such method is to load the XSLT stylesheet as an XmlDocument, and using the available DOM methods for access to and modification of attributes, to set the href attribute to the desired value. Then initiate the transformation from this in-memory-modified XMLDocument-contained XSLT stylesheet.

一种这样的方法是将XSLT样式表加载为XmlDocument,并使用可用的DOM方法来访问和修改属性,以将href属性设置为所需的值。然后从这个内存中修改的XMLDocument包含的XSLT样式表启动转换。

#2


3  

As I understand things, 'include' happens when the xml parser is parsing and compiling the style sheet. This means that no logic or expression evaluation can happen before the include gets processed and therefore there's no way to make it conditional as such. You need to make the conditional behavior happen outside of the style sheet.

据我所知,当xml解析器解析并编译样式表时,会发生'include'。这意味着在处理包之前不会发生逻辑或表达式评估,因此无法使其成为条件。您需要使条件行为发生在样式表之外。

Have a look at this http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6065e100

看看这个http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6065e100

In particular does this comment by Mike Kay help:

特别是Mike Kay的评论帮助:

This has been raised a number of times. On a previous thread we came to the conclusion that the user was trying to write a general-purpose stylesheet G and then specialize it by conditionally including a special-purpose stylesheet A or B. The way to meet this requirement is to have A and B include G, not the other way around, and then you conditionally select A or B as the principal stylesheet when starting the transformation.

这已经提出了很多次。在前一个帖子中,我们得出的结论是,用户试图编写通用样式表G,然后通过有条件地包括专用样式表A或B来专门化它。满足此要求的方法是使用A和B包括G,而不是相反,然后在开始转换时有条件地选择A或B作为主要样式表。

#3


3  

Try inverting the structure: if you have two special purpose modules pink.xsl and blue.xsl, and a general-purpose module baby.xsl, then instead of trying to import/include one of pink.xsl or blue.xsl into baby.xsl, instead use pink.xsl or blue.xsl as the top-level entry stylesheet, and have each of these two import baby.xsl. That's the way it was designed to be used, it's nto a hack or a workaround.

尝试反转结构:如果你有两个特殊用途模块pink.xsl和blue.xsl,以及一个通用模块baby.xsl,那么不要试图导入/包含pink.xsl或blue.xsl中的一个到baby。 xsl,而是使用pink.xsl或blue.xsl作为*条目样式表,并将这两个中的每一个导入baby.xsl。这是它被设计使用的方式,它是一个黑客或解决方法。

Alternatively, given this description of your scenario "My external xml file is a bunch of xslt code fragments", a better approach in your case might be to assemble the stylesheet from these fragments as a separate step, using an XSLT tranformation rather than using xsl:include/xsl:import.

或者,鉴于您的场景“我的外部xml文件是一堆xslt代码片段”的描述,在您的情况下,更好的方法可能是使用XSLT转换而不是使用xsl从这些片段组装样式表作为单独的步骤:包括/ XSL:进口。

#4


1  

Not sure if this would apply to your scenario, but I'm going to throw this out there anyways.

不确定这是否适用于您的场景,但无论如何我都会把它扔出去。

I've done similar things in the past, but instead of doing a conditional include, I call a template in either one of the two files based on what the xsl:when evaluates to. If you don't want to use templates in your case, disregard this answer.

我过去做过类似的事情,但是我没有做一个有条件的包含,而是根据xsl:when的计算结果在两个文件中的任何一个中调用模板。如果您不想在您的案例中使用模板,请忽略此答案。

For instance, say the "parent" xslt file is called root.xslt, and the two conditionally-used ones are child1.xslt and child2.xslt. Say I want to run conditional logic against the value of a node called status. If the value is "CURRENT", I want to call a template called isCurrent in child1.xslt, otherwise call a template called isNotCurrent in child2.xslt. For the sake of brevity, in each case I'm simply passing the template the root node and all children.

例如,假设“parent”xslt文件名为root.xslt,两个有条件使用的文件名为child1.xslt和child2.xslt。假设我想针对名为status的节点的值运行条件逻辑。如果值为“CURRENT”,我想在child1.xslt中调用名为isCurrent的模板,否则在child2.xslt中调用名为isNotCurrent的模板。为了简洁起见,在每种情况下,我只是将模板传递给根节点和所有子节点。

It'd look something like this:

它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:import href="child1.xslt"/>
    <xsl:import href="child2.xslt"/>

    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="rootNode/status = 'CURRENT'">
          <!-- template isCurrent defined in child1.xslt -->
          <xsl:apply-templates select="rootNode" mode="isCurrent" />
        </xsl:when>
        <xsl:otherwise>
          <!-- template isNotCurrent defined in child2.xslt -->
          <xsl:apply-templates select="rootNode" mode="isNotCurrent" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Hope this at least helps a little bit.

希望这至少有点帮助。

#5


0  

In addition to what already has been said, a possible solution would be to make the supplementary files to be plain, content-providing XML files (instead of XSLT files). That way, you can include them with XPath's document() function (which will be evaluated at run-time rather than compile-time).

除了已经说过的内容之外,一个可能的解决方案是使补充文件成为简单的,提供内容的XML文件(而不是XSLT文件)。这样,您可以将它们包含在XPath的document()函数中(将在运行时而不是在编译时进行评估)。

You can then alter the behavior of your transformation based on the contents of the loaded XML document; however, you cannot provide executable XSLT fragments in the included documents.

然后,您可以根据加载的XML文档的内容更改转换的行为;但是,您无法在包含的文档中提供可执行的XSLT片段。

It depends on your use-case whether this is a solution - if the additional documents have a strong impact on the control flow of your transformation, you don't want to define them in plain XML, because you basically would re-implement something like XSLT. However, when your documents serve as kind of configuration files, you might want to think about providing them als pure XML.

这取决于你的用例是否这是一个解决方案 - 如果其他文档对转换的控制流有很大的影响,你不想用简单的XML定义它们,因为你基本上会重新实现像XSLT。但是,当您的文档作为一种配置文件时,您可能想要考虑为它们提供纯XML。

When you're having problems with document(), use an XML validator on your files. An error implies that your files are not valid XML.

当您遇到document()问题时,请在文件上使用XML验证程序。错误意味着您的文件不是有效的XML。

#6


0  

<xsl:variable name="CONDITIONAL" select="ELEMENT/CONDITION"/>
<xsl:variable name="DOCUMENTNAME" select="document(concat($CONDITIONAL,'-DOCUMENT.xml'))/ELEMENT"/>

This example is how I did a conditional use of an external file. I had the flag in the base XML that the XSL uses as a variable to help specify the name of the other file to pull into the template. Once that variable is defined as in my case I use it to pull other XML data into the generated output. The concat command forces the data together to give a file name.

这个例子是我如何有条件地使用外部文件。我在基本XML中有一个标志,XSL将其用作变量,以帮助指定要插入模板的另一个文件的名称。一旦在我的情况下定义了该变量,我就用它将其他XML数据拉入生成的输出中。 concat命令强制数据一起提供文件名。

So When I want info from the external XML file I use '$DOCUMENTNAME' for referencing the external data.

因此,当我需要外部XML文件的信息时,我使用'$ DOCUMENTNAME'来引用外部数据。

#7


0  

With the addition of static parameters, this is now possible in XSLT 3.0. Static parameters can be used in the use-when attribute of the xsl:include.

通过添加静态参数,现在可以在XSLT 3.0中实现。静态参数可以在xsl:include的use-when属性中使用。

Now we can declare parameters with default values of false() and then override the ones we need at run time...

现在我们可以使用默认值false()声明参数,然后在运行时覆盖我们需要的参数...

<xsl:param name="someparam" as="xs:boolean" select="false()" 
  static="yes" required="no"/>  
<xsl:include href="include_me.xsl" use-when="$someparam"/>

Here is a full working example tested with Saxon-HE v9.7 (also tested with Saxon-PE 9.5).

这是一个完整的工作示例,使用Saxon-HE v9.7(也使用Saxon-PE 9.5测试)进行了测试。

XML Input (test.xml)

XML输入(test.xml)

<doc>
    <foo/>
</doc>

Main XSLT 3.0 (test_main.xsl)

主XSLT 3.0(test_main.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="inc1" as="xs:boolean" select="false()" 
    static="yes" required="no"/>
  <xsl:param name="inc2" as="xs:boolean" select="false()" 
    static="yes" required="no"/>

  <xsl:include href="test_inc1.xsl" use-when="$inc1"/>
  <xsl:include href="test_inc2.xsl" use-when="$inc2"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

First possible included XSLT 3.0 (test_inc1.xsl)

首先可能包括XSLT 3.0(test_inc1.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="foo">
    <xsl:copy>INCLUDE FILE 1!!!</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Second possible included XSLT 3.0 (test_inc2.xsl)

第二种可能包括XSLT 3.0(test_inc2.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="foo">
    <xsl:copy>INCLUDE FILE 2!!!</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Command line (setting inc2 to true)

命令行(将inc2设置为true)

java -cp "saxon9he.jar" net.sf.saxon.Transform -s:"test.xml" -xsl:"test_main.xsl" inc2="true"

Output

产量

<doc>
   <foo>INCLUDE FILE 2!!!</foo>
</doc>

#8


0  

There is one approach I have found to conditionally include files using use-when feature in XSLT 2.0.

我发现有一种方法可以在XSLT 2.0中使用use-when功能有条件地包含文件。

You have to create one system property which is passed through the Application at runtime, like in my case I am using Java so I have created "Debug" property using command to run my application:

你必须创建一个在运行时通过Application传递的系统属性,就像我使用Java一样,所以我使用命令创建了“Debug”属性来运行我的应用程序:

java -DDebug=yes myAppPath

then in XSLT use this property to include conditional files. For example

然后在XSLT中使用此属性来包含条件文件。例如

<xsl:include href="file1.xslt" use-when="system-property('DEBUG') = 'yes'"/>
<xsl:include href="file2.xslt" use-when="system-property('DEBUG') != 'yes'"/>

like that.

像那样。

Don't know if it fits for asked scenario but YES there is way to do it in XSLT 2.0. In XSLT 3.0, support for local variable is also added. So this can be easily done there using local variables.

不知道它是否适合问题场景,但是在XSLT 2.0中有可行的方法。在XSLT 3.0中,还添加了对局部变量的支持。所以这可以使用局部变量轻松完成。

Thanks, Happy Coding

谢谢,快乐编码

#1


6  

This cannot be done with XSLT 1.0 and can be done (to a very limited extent) in XSLT 2.0 using the use-when attribute.

这不能用XSLT 1.0完成,并且可以使用use-when属性在XSLT 2.0中完成(在非常有限的范围内)。

There exist non-xslt ways of achieving the wanted dynamic altering of an xsl:include or an xsl:import directive.

存在非xslt方法来实现xsl:include或xsl:import指令的所需动态更改。

One such method is to load the XSLT stylesheet as an XmlDocument, and using the available DOM methods for access to and modification of attributes, to set the href attribute to the desired value. Then initiate the transformation from this in-memory-modified XMLDocument-contained XSLT stylesheet.

一种这样的方法是将XSLT样式表加载为XmlDocument,并使用可用的DOM方法来访问和修改属性,以将href属性设置为所需的值。然后从这个内存中修改的XMLDocument包含的XSLT样式表启动转换。

#2


3  

As I understand things, 'include' happens when the xml parser is parsing and compiling the style sheet. This means that no logic or expression evaluation can happen before the include gets processed and therefore there's no way to make it conditional as such. You need to make the conditional behavior happen outside of the style sheet.

据我所知,当xml解析器解析并编译样式表时,会发生'include'。这意味着在处理包之前不会发生逻辑或表达式评估,因此无法使其成为条件。您需要使条件行为发生在样式表之外。

Have a look at this http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6065e100

看看这个http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6065e100

In particular does this comment by Mike Kay help:

特别是Mike Kay的评论帮助:

This has been raised a number of times. On a previous thread we came to the conclusion that the user was trying to write a general-purpose stylesheet G and then specialize it by conditionally including a special-purpose stylesheet A or B. The way to meet this requirement is to have A and B include G, not the other way around, and then you conditionally select A or B as the principal stylesheet when starting the transformation.

这已经提出了很多次。在前一个帖子中,我们得出的结论是,用户试图编写通用样式表G,然后通过有条件地包括专用样式表A或B来专门化它。满足此要求的方法是使用A和B包括G,而不是相反,然后在开始转换时有条件地选择A或B作为主要样式表。

#3


3  

Try inverting the structure: if you have two special purpose modules pink.xsl and blue.xsl, and a general-purpose module baby.xsl, then instead of trying to import/include one of pink.xsl or blue.xsl into baby.xsl, instead use pink.xsl or blue.xsl as the top-level entry stylesheet, and have each of these two import baby.xsl. That's the way it was designed to be used, it's nto a hack or a workaround.

尝试反转结构:如果你有两个特殊用途模块pink.xsl和blue.xsl,以及一个通用模块baby.xsl,那么不要试图导入/包含pink.xsl或blue.xsl中的一个到baby。 xsl,而是使用pink.xsl或blue.xsl作为*条目样式表,并将这两个中的每一个导入baby.xsl。这是它被设计使用的方式,它是一个黑客或解决方法。

Alternatively, given this description of your scenario "My external xml file is a bunch of xslt code fragments", a better approach in your case might be to assemble the stylesheet from these fragments as a separate step, using an XSLT tranformation rather than using xsl:include/xsl:import.

或者,鉴于您的场景“我的外部xml文件是一堆xslt代码片段”的描述,在您的情况下,更好的方法可能是使用XSLT转换而不是使用xsl从这些片段组装样式表作为单独的步骤:包括/ XSL:进口。

#4


1  

Not sure if this would apply to your scenario, but I'm going to throw this out there anyways.

不确定这是否适用于您的场景,但无论如何我都会把它扔出去。

I've done similar things in the past, but instead of doing a conditional include, I call a template in either one of the two files based on what the xsl:when evaluates to. If you don't want to use templates in your case, disregard this answer.

我过去做过类似的事情,但是我没有做一个有条件的包含,而是根据xsl:when的计算结果在两个文件中的任何一个中调用模板。如果您不想在您的案例中使用模板,请忽略此答案。

For instance, say the "parent" xslt file is called root.xslt, and the two conditionally-used ones are child1.xslt and child2.xslt. Say I want to run conditional logic against the value of a node called status. If the value is "CURRENT", I want to call a template called isCurrent in child1.xslt, otherwise call a template called isNotCurrent in child2.xslt. For the sake of brevity, in each case I'm simply passing the template the root node and all children.

例如,假设“parent”xslt文件名为root.xslt,两个有条件使用的文件名为child1.xslt和child2.xslt。假设我想针对名为status的节点的值运行条件逻辑。如果值为“CURRENT”,我想在child1.xslt中调用名为isCurrent的模板,否则在child2.xslt中调用名为isNotCurrent的模板。为了简洁起见,在每种情况下,我只是将模板传递给根节点和所有子节点。

It'd look something like this:

它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:import href="child1.xslt"/>
    <xsl:import href="child2.xslt"/>

    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="rootNode/status = 'CURRENT'">
          <!-- template isCurrent defined in child1.xslt -->
          <xsl:apply-templates select="rootNode" mode="isCurrent" />
        </xsl:when>
        <xsl:otherwise>
          <!-- template isNotCurrent defined in child2.xslt -->
          <xsl:apply-templates select="rootNode" mode="isNotCurrent" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Hope this at least helps a little bit.

希望这至少有点帮助。

#5


0  

In addition to what already has been said, a possible solution would be to make the supplementary files to be plain, content-providing XML files (instead of XSLT files). That way, you can include them with XPath's document() function (which will be evaluated at run-time rather than compile-time).

除了已经说过的内容之外,一个可能的解决方案是使补充文件成为简单的,提供内容的XML文件(而不是XSLT文件)。这样,您可以将它们包含在XPath的document()函数中(将在运行时而不是在编译时进行评估)。

You can then alter the behavior of your transformation based on the contents of the loaded XML document; however, you cannot provide executable XSLT fragments in the included documents.

然后,您可以根据加载的XML文档的内容更改转换的行为;但是,您无法在包含的文档中提供可执行的XSLT片段。

It depends on your use-case whether this is a solution - if the additional documents have a strong impact on the control flow of your transformation, you don't want to define them in plain XML, because you basically would re-implement something like XSLT. However, when your documents serve as kind of configuration files, you might want to think about providing them als pure XML.

这取决于你的用例是否这是一个解决方案 - 如果其他文档对转换的控制流有很大的影响,你不想用简单的XML定义它们,因为你基本上会重新实现像XSLT。但是,当您的文档作为一种配置文件时,您可能想要考虑为它们提供纯XML。

When you're having problems with document(), use an XML validator on your files. An error implies that your files are not valid XML.

当您遇到document()问题时,请在文件上使用XML验证程序。错误意味着您的文件不是有效的XML。

#6


0  

<xsl:variable name="CONDITIONAL" select="ELEMENT/CONDITION"/>
<xsl:variable name="DOCUMENTNAME" select="document(concat($CONDITIONAL,'-DOCUMENT.xml'))/ELEMENT"/>

This example is how I did a conditional use of an external file. I had the flag in the base XML that the XSL uses as a variable to help specify the name of the other file to pull into the template. Once that variable is defined as in my case I use it to pull other XML data into the generated output. The concat command forces the data together to give a file name.

这个例子是我如何有条件地使用外部文件。我在基本XML中有一个标志,XSL将其用作变量,以帮助指定要插入模板的另一个文件的名称。一旦在我的情况下定义了该变量,我就用它将其他XML数据拉入生成的输出中。 concat命令强制数据一起提供文件名。

So When I want info from the external XML file I use '$DOCUMENTNAME' for referencing the external data.

因此,当我需要外部XML文件的信息时,我使用'$ DOCUMENTNAME'来引用外部数据。

#7


0  

With the addition of static parameters, this is now possible in XSLT 3.0. Static parameters can be used in the use-when attribute of the xsl:include.

通过添加静态参数,现在可以在XSLT 3.0中实现。静态参数可以在xsl:include的use-when属性中使用。

Now we can declare parameters with default values of false() and then override the ones we need at run time...

现在我们可以使用默认值false()声明参数,然后在运行时覆盖我们需要的参数...

<xsl:param name="someparam" as="xs:boolean" select="false()" 
  static="yes" required="no"/>  
<xsl:include href="include_me.xsl" use-when="$someparam"/>

Here is a full working example tested with Saxon-HE v9.7 (also tested with Saxon-PE 9.5).

这是一个完整的工作示例,使用Saxon-HE v9.7(也使用Saxon-PE 9.5测试)进行了测试。

XML Input (test.xml)

XML输入(test.xml)

<doc>
    <foo/>
</doc>

Main XSLT 3.0 (test_main.xsl)

主XSLT 3.0(test_main.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="inc1" as="xs:boolean" select="false()" 
    static="yes" required="no"/>
  <xsl:param name="inc2" as="xs:boolean" select="false()" 
    static="yes" required="no"/>

  <xsl:include href="test_inc1.xsl" use-when="$inc1"/>
  <xsl:include href="test_inc2.xsl" use-when="$inc2"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

First possible included XSLT 3.0 (test_inc1.xsl)

首先可能包括XSLT 3.0(test_inc1.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="foo">
    <xsl:copy>INCLUDE FILE 1!!!</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Second possible included XSLT 3.0 (test_inc2.xsl)

第二种可能包括XSLT 3.0(test_inc2.xsl)

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="foo">
    <xsl:copy>INCLUDE FILE 2!!!</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Command line (setting inc2 to true)

命令行(将inc2设置为true)

java -cp "saxon9he.jar" net.sf.saxon.Transform -s:"test.xml" -xsl:"test_main.xsl" inc2="true"

Output

产量

<doc>
   <foo>INCLUDE FILE 2!!!</foo>
</doc>

#8


0  

There is one approach I have found to conditionally include files using use-when feature in XSLT 2.0.

我发现有一种方法可以在XSLT 2.0中使用use-when功能有条件地包含文件。

You have to create one system property which is passed through the Application at runtime, like in my case I am using Java so I have created "Debug" property using command to run my application:

你必须创建一个在运行时通过Application传递的系统属性,就像我使用Java一样,所以我使用命令创建了“Debug”属性来运行我的应用程序:

java -DDebug=yes myAppPath

then in XSLT use this property to include conditional files. For example

然后在XSLT中使用此属性来包含条件文件。例如

<xsl:include href="file1.xslt" use-when="system-property('DEBUG') = 'yes'"/>
<xsl:include href="file2.xslt" use-when="system-property('DEBUG') != 'yes'"/>

like that.

像那样。

Don't know if it fits for asked scenario but YES there is way to do it in XSLT 2.0. In XSLT 3.0, support for local variable is also added. So this can be easily done there using local variables.

不知道它是否适合问题场景,但是在XSLT 2.0中有可行的方法。在XSLT 3.0中,还添加了对局部变量的支持。所以这可以使用局部变量轻松完成。

Thanks, Happy Coding

谢谢,快乐编码