Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 如何在xsl中测试带名称空间的元素名_Xslt - Fatal编程技术网

Xslt 如何在xsl中测试带名称空间的元素名

Xslt 如何在xsl中测试带名称空间的元素名,xslt,Xslt,我正在做一些xforms开发,并且有一个与所选项目匹配的模板。如果是单选而不是多选,我想在给定列表的顶部添加一个空值: <xsl:template match="xforms:select1|xforms:select"> <xsl:apply-templates select="node()" /> <xsl:if test=".[name()='xf:select1'] and not (@appearance eq 'full')">

我正在做一些xforms开发,并且有一个与所选项目匹配的模板。如果是单选而不是多选,我想在给定列表的顶部添加一个空值:

<xsl:template match="xforms:select1|xforms:select">
    <xsl:apply-templates select="node()" />
    <xsl:if test=".[name()='xf:select1'] and not (@appearance eq 'full')">
        <xforms:item>
            <xforms:label />
            <xforms:value />
        </xforms:item>
    </xsl:if>
    ...

...
问题是,这对我的一个表单有效,该表单具有
xf:select1
(因为
match
可识别名称空间),但另一个表单中的
xforms:select1
控件被破坏,因为
name()
测试仅用于字符串


有没有一种方法可以使这个if语句工作,而不管我为
http://www.w3.org/2002/xforms
名称空间?

我所做的是将if拆分为不同的模板。。。我喜欢它,因为它是xsl的目标;我讨厌它,因为它是一些匹配逻辑的另一个副本,如果它有缺陷或改进,就必须在多个地方进行更改

<xsl:template match="xforms:select1[not(xforms:itemset) and not(@appearance eq 'full')]" priority="10">
    <xsl:apply-templates select="node()" />
    <xforms:item>
        <xforms:label />
        <xforms:value />
    </xforms:item>
    <xsl:call-template name="select-itemset"/>
</xsl:template> 

<xsl:template match="xforms:select1[not(xforms:itemset)]|xforms:select[not(xforms:itemset)]">
    <xsl:apply-templates select="node()" />
    <xsl:call-template name="select-itemset"/>
</xsl:template>

<xsl:template name="select-itemset">
    ...

...

我所做的是将if拆分为不同的模板。。。我喜欢它,因为它是xsl的目标;我讨厌它,因为它是一些匹配逻辑的另一个副本,如果它有缺陷或改进,就必须在多个地方进行更改

<xsl:template match="xforms:select1[not(xforms:itemset) and not(@appearance eq 'full')]" priority="10">
    <xsl:apply-templates select="node()" />
    <xforms:item>
        <xforms:label />
        <xforms:value />
    </xforms:item>
    <xsl:call-template name="select-itemset"/>
</xsl:template> 

<xsl:template match="xforms:select1[not(xforms:itemset)]|xforms:select[not(xforms:itemset)]">
    <xsl:apply-templates select="node()" />
    <xsl:call-template name="select-itemset"/>
</xsl:template>

<xsl:template name="select-itemset">
    ...

...

您肯定希望避免任何依赖命名空间前缀的代码。我想您应该使用自轴:

<xsl:if test="self::xforms:select1 and not (@appearance eq 'full')">

您肯定希望避免任何依赖命名空间前缀的代码。我想您应该使用自轴:

<xsl:if test="self::xforms:select1 and not (@appearance eq 'full')">