Skip to main content
Participant
August 19, 2025
Question

Drop an element based on the value of an attribute but retain children

  • August 19, 2025
  • 3 replies
  • 190 views

Hi there,

Brand new to FrameMaker and grateful for any help!

I have several elements that contain text in my XML that I want FrameMaker to omit if the attribute display="false" is present? Can I drop/omit an element based on an attribute's value, but not drop the child element?

 

example:

<option1>
  <feedisplay display="true">Text in the output</feedisplay>
    <option2>
      <feedisplay display="true">Text in the output</feedisplay>
        <option3>
          <feedisplay display="false">Text I want ignored/omitted in the output</feedisplay>
            <option4>
              <feedisplay display="true">Text in the output</feedisplay>

 

    3 replies

    frameexpert
    Community Expert
    Community Expert
    August 20, 2025

    This XSL stylesheet, which can be applied to your content on export to XML,

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        exclude-result-prefixes="xs"
        version="3.0">
        
        <xsl:output indent="1"/>
        
        <xsl:template match="feedisplay[@display='false']">
            <xsl:apply-templates select="*"/>
        </xsl:template>    
        
        <xsl:mode on-no-match="shallow-copy"/>
        
    </xsl:stylesheet>

    will give you this output:

    <?xml version="1.0" encoding="UTF-8"?>
    <option1>
       <feedisplay display="true">Text in the output</feedisplay>
       <option2>
          <feedisplay display="true">Text in the output</feedisplay>
          <option3>
             <option4>
                <feedisplay display="true">Text in the output</feedisplay>
             </option4>
          </option3>
       </option2>
    </option1>
    
    frameexpert
    Community Expert
    Community Expert
    August 19, 2025

    Would this be your sample input with the nesting in place?

    <?xml version="1.0" encoding="UTF-8"?>
    <option1>
        <feedisplay display="true">Text in the output</feedisplay>
        <option2>
            <feedisplay display="true">Text in the output</feedisplay>
            <option3>
                <feedisplay display="false">Text I want ignored/omitted in the output</feedisplay>
                <option4>
                    <feedisplay display="true">Text in the output</feedisplay>
                </option4>
            </option3>
        </option2>
    </option1>
    Participant
    August 20, 2025

    Good morning Frameexpert!

    Yes, your example of the input is correct. Thank you for your help! I've tried drop and unwrap with no such luck. I'm importing the XML and the output is a pdf which I do not want that text included in. I hope that helps clarify things. 🙂

    frameexpert
    Community Expert
    Community Expert
    August 19, 2025

    Do you want to omit it from FrameMaker on import from XML? Or do you want to see it in FrameMaker but omit it when you save as XML?

     

    Either way, can you post an after sample of your XML? Thanks.