xsl:stylesheet中的条件



我有几个相同的文件,但有一点不同。这些文件之间的唯一区别是xsl:stylesheet中的声明。示例:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:sf="http://www.company.pl/sf"
xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo" xmlns:iit="http://www.abc.qwerty.com/scheme/AFQ/DataTypeStructureDef/2018/07/09/InsuranceInThousands" xmlns:is="http://www.abc.qwerty.com/scheme/AFQ/DataTypeStructureDef/2018/07/09/InsuranceStruct">

而在其他文件中,我只有iit参数的差异

xmlns:iit="http://www.abc.qwerty.com/scheme/AFQ/DataTypeStructureDef/2018/07/09/InsuranceInHundreds" 

实际上,我有很多相同的文件,只有一个不同。。。在其他情况下,我通过将param传递给xslt来解决这个问题,例如:

<xsl:param name="tagCount"/>

但是在xsl:stylesheet中,我不知道是否可以传递params并添加If条件?我怎样才能达到这种效果?

当您处理多个结构非常相似但名称空间URI不同的源文档时,我认为最好的策略通常是对源文档进行预处理,使它们都使用相同的名称空间URI。这可以通过这样一个简单的转换来完成:

<xsl:param name="input-namespace"/>
<xsl:param name="output-namespace"/>
<xsl:template match="*[namespace-uri() = $input-namespace]">
<xsl:element name="name()" namespace-uri="{$output-namespace}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

或者,编写一个SAX过滤器。

一旦消除了名称空间的差异,主样式表就会变得更加简单和不那么杂乱。

最新更新