Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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删除属性_Xslt_Xpath - Fatal编程技术网

如果存在祖先,则XSLT删除属性

如果存在祖先,则XSLT删除属性,xslt,xpath,Xslt,Xpath,我正试图根据祖先的名称从节点中删除属性 这是我的模板。我正在尝试删除所有minOccurrs属性,除非祖先是updateCurrentObjective <xsl:template match="@minOccurs"> <xsl:if test="0 = count(ancestor::node()[name() = 'updateCurrentObjective'])"> <xsl:copy/> </xsl:if>

我正试图根据祖先的名称从节点中删除属性

这是我的模板。我正在尝试删除所有
minOccurrs
属性,除非祖先是
updateCurrentObjective

<xsl:template match="@minOccurs">
    <xsl:if test="0 = count(ancestor::node()[name() = 'updateCurrentObjective'])">
        <xsl:copy/>
    </xsl:if>
</xsl:template>

因此,对于下面的XML,它应该删除该属性

  <xs:extension base="tns:planElement">
    <xs:sequence>
      <xs:element minOccurs="0" name="action" type="xs:string"/>
    </xs:sequence>
  <xs:extension>

但对于以下情况,应保持原样

  <xs:complexType name="updateCurrentObjective">
    <xs:sequence>
      <xs:element minOccurs="0" name="currentObjective" type="tns:objective"/>
    </xs:sequence>
  </xs:complexType>


想法?

这应该可以。也可以将谓词放入模板匹配中,但我无法做到这一点

我还假设您正在尝试转换
xsd
本身(而不是与之匹配的文档实例)



基本上,从元素追溯到父元素,然后查看其祖先是否具有属性
name='updateCurrentObjective'
。如果可以,可以使用更具体的元素名称替换
*

是否要操作架构?在这种情况下,我认为不会有一个祖先具有
name()=“updateCurrentObjective”
,而是会有一个元素具有
@name=“updateCurrentObjective”

所以使用

<xsl:template match="@minOccurs[not(ancestor::*[@name = 'updateCurrentObjective'])]"/>


为了避免复制minOccurs属性。

我有两个模板规则:

<xsl:template match="@minOccurs"/>

<xsl:template match="*[@name='updateCurrentObjective']//@minOccurs">
    <xsl:copy/>
</xsl:template>

<xsl:template match="@minOccurs"/>

<xsl:template match="*[@name='updateCurrentObjective']//@minOccurs">
    <xsl:copy/>
</xsl:template>