DFDL is pretty limited when it comes to ignoring things in the infoset. I can't think of a good way to do what you're suggesting.

I think generally the recommended approach for something like this is to filter the infoset prior to unparsing. For example, an XSLT could do what you want in one line (with the rest being standard XSLT boilerplate):

  <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

    <!-- override to not copy "person" elements where rsvp is not "Yes" -->
    <xsl:template match="person[not(rsvp='Yes')]" />

  </xsl:stylesheet>

There's a lot of things to dislike about XSLT, but is pretty powerful when it comes to filtering XML, so generally makes it a better tool for that kindof thing than DFDL.

You aren't limited to XSLT though--languages like Python/Javascript/Scala have good XML support for finding and removing elements, so that is also an option. Though they usually require a few more lines of code than XSLT and aren't declarative like XSLT and DFDL, which has advantages.

On 2025-10-02 09:01 AM, Mark Kozak wrote:
Hello community,

I have a situation where I would like to discard parts of a parsed data file if that part is invalid. After trying several approaches using hidden groups and output value calculations, I am starting to think it just can’t be done. But I wanted to check with the community before I hang up the effort.

Below is a simplified example of a schema that will illustrate the use case. Suppose we have a file of names and want to unparse only the elements where RSVP is equal to ‘Yes’. Not being able to use dfdl:inputValueCalc on a complex type appears to be a limiting factor here. In the real world the complex types are quite complex so copying each simple element in the array one by one is untenable.

Any shared thoughts will be very much appreciated.

Thanks,

Mark

Mark Kozak

Director of Engineering

Adeptus Cyber Solutions

Adeptus-CS.com


Reply via email to