Copy the parent containing the specific child using xslt

I have a simple xml:

<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>

I am trying to simply copy every element <custom-object>that contains a child element, where @attribute-id- "exportdate", and has a specific text value.

Here is my xslt:

<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>

The match works when used as an xpath. Xslt returns an empty result.

  • Why does this not work in this case?
  • Where is my mistake?
+4
source share
1 answer

"I'm trying to just copy every element containing a child element, where @ attribute-id is" exportdate "and has a specific text value."

. , XSL custom-object, "exportdate" "2015-09-19", . , XPath , :

<xsl:template 
    match="custom-object[not(object-attribute[@attribute-id='exportdate']='2015-09-19')]"/>
+2

All Articles