首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用xslt复制包含特定子元素的父元素

使用xslt复制包含特定子元素的父元素
EN

Stack Overflow用户
提问于 2016-05-10 07:36:55
回答 1查看 691关注 0票数 4

我有一个简单的xml:

代码语言:javascript
复制
<custom-objects>
    <custom-object id="1">
        <object-attribute attribute-id="address1">Warndtstr. 33</object-attribute>
        <object-attribute attribute-id="branch">01</object-attribute>
        <object-attribute attribute-id="catalogid">7991</object-attribute>
        <object-attribute attribute-id="exportdate">2015-09-19</object-attribute>
    </custom-object>
    <custom-object>
...
    </custom-object>
</custom-objects>

我试图简单地复制每个<custom-object>元素,其中包含一个子元素,其中@attribute-id"exportdate",并且有一个特定的文本值。

以下是我的xslt:

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="custom-object[object-attribute[@attribute-id='exportdate']='2015-09-19']"/>
</xsl:stylesheet>

当使用xpath时,匹配是有效的。xslt返回一个空结果。

  • 为什么在这种情况下不行呢?
  • 我的错误在哪里?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-10 07:43:22

“我试图简单地复制每个包含@attribute-id为"exportdate”并具有特定文本值的子元素。“

应该用于删除元素的空模板。因此,当前,XSL应该删除“exportdate”等于“2015-09-19”的custom-object,并复制其他元素。如果您希望相反,请尝试使用具有相反含义的XPath,例如:

代码语言:javascript
复制
<xsl:template 
    match="custom-object[not(object-attribute[@attribute-id='exportdate']='2015-09-19')]"/>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37132078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档