Repository: dita-ot/dita-ot
Issue: Flagging does not work with specialized attribute

## Expected Behavior
When multiple flags apply to a single element, multiple flags should be rendered, typically in the order that they are encountered.
https://docs.oasis-open.org/dita/dita/v1.3/errata02/os/complete/part3-all-inclusive/archSpec/base/flagging.html#flagging

## Actual Behavior
When multiple flags apply to a single element, some flags are ignored if the attribute is speicalized.

In the test case attahced, flagging does not work as expected for last paragraph. Here `newAtt` is specialized from `props`.
```
<p class="- topic/p " platform="windows">1. platform="windows"</p>
<p class="- topic/p " audience="novice">2. audience="novice"</p>
<p class="- topic/p " newAtt="aaa">3. newAtt="(aaa)"</p>
<p class="- topic/p " platform="windows" audience="novice">4. platform="windows" and audience="novice"</p>
<p class="- topic/p " platform="windows" newAtt="aaa">5. platform="windows" and newAtt="aaa"</p>   
```

## Possible Solution
N/A

## Steps to Reproduce
Test case and the project file is attached. 
[test.zip](https://github.com/dita-ot/dita-ot/files/9977643/test.zip)

`dita --project=project.xml`

## Copy of the error message, log file or stack trace
N/A

## Environment
* DITA-OT version: 3.4.1
* Operating system and version: Windows
* How did you run DITA-OT?  'dita' command
* Transformation type: PDF


Changed files:
src/test/java/org/dita/dost/util/FilterUtilsTest.java, src/main/java/org/dita/dost/util/FilterUtils.java

diff --git a/src/main/java/org/dita/dost/util/FilterUtils.java b/src/main/java/org/dita/dost/util/FilterUtils.java
index 8c1f0be93..ce05de7c0 100644
--- a/src/main/java/org/dita/dost/util/FilterUtils.java
+++ b/src/main/java/org/dita/dost/util/FilterUtils.java
@@ -182,21 +182,19 @@ public final class FilterUtils {
                 }
             }
         }
-        if (res.isEmpty()) {
-            if (extProps != null && extProps.length != 0) {
-                for (final QName[] propList : extProps) {
-                    int propListIndex = propList.length - 1;
-                    final QName propName = propList[propListIndex];
-                    String propValue = atts.getValue(propName.getNamespaceURI(), propName.getLocalPart());
-
-                    while ((propValue == null || propValue.trim().isEmpty()) && propListIndex > 0) {
-                        propListIndex--;
-                        final QName current = propList[propListIndex];
-                        propValue = getLabelValue(propName, atts.getValue(current.getNamespaceURI(), current.getLocalPart()));
-                    }
-                    if (propValue != null) {
-                        res.addAll(extCheckFlag(propList, Arrays.asList(propValue.split("\\\\s+"))));
-                    }
+        if (extProps != null && extProps.length != 0) {
+            for (final QName[] propList : extProps) {
+                int propListIndex = propList.length - 1;
+                final QName propName = propList[propListIndex];
+                String propValue = atts.getValue(propName.getNamespaceURI(), propName.getLocalPart());
+
+                while ((propValue == null || propValue.trim().isEmpty()) && propListIndex > 0) {
+                    propListIndex--;
+                    final QName current = propList[propListIndex];
+                    propValue = getLabelValue(propName, atts.getValue(current.getNamespaceURI(), current.getLocalPart()));
+                }
+                if (propValue != null) {
+                    res.addAll(extCheckFlag(propList, Arrays.asList(propValue.split("\\\\s+"))));
                 }
             }
         }
diff --git a/src/test/java/org/dita/dost/util/FilterUtilsTest.java b/src/test/java/org/dita/dost/util/FilterUtilsTest.java
index a55d07cbc..55d10c522 100644
--- a/src/test/java/org/dita/dost/util/FilterUtilsTest.java
+++ b/src/test/java/org/dita/dost/util/FilterUtilsTest.java
@@ -7,31 +7,28 @@
  */
 package org.dita.dost.util;
 
-import static java.util.Arrays.asList;
-import static java.util.Collections.*;
-import static javax.xml.XMLConstants.XML_NS_PREFIX;
-import static javax.xml.XMLConstants.XML_NS_URI;
-import static org.dita.dost.util.Constants.*;
-import static org.junit.Assert.*;
-
-import java.util.*;
-import java.util.stream.Stream;
-
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import org.dita.dost.TestUtils;
 import org.dita.dost.util.FilterUtils.Action;
 import org.dita.dost.util.FilterUtils.FilterKey;
-
 import org.dita.dost.util.FilterUtils.Flag;
 import org.dita.dost.util.XMLUtils.AttributesBuilder;
+import org.junit.Test;
 import org.xml.sax.Attributes;
 import org.xml.sax.helpers.AttributesImpl;
 
-import org.junit.Test;
-
-import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
+import java.util.*;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.singleton;
+import static javax.xml.XMLConstants.XML_NS_PREFIX;
+import static javax.xml.XMLConstants.XML_NS_URI;
+import static org.dita.dost.util.Constants.ATTRIBUTE_NAME_PLATFORM;
+import static org.dita.dost.util.Constants.ATTRIBUTE_NAME_REV;
+import static org.junit.Assert.*;
 
 public class FilterUtilsTest {
 
@@ -246,6 +243,23 @@ public class FilterUtilsTest {
                 f.getFlags(attr(PLATFORM, "windows"), new QName[0][0]));
     }
 
+    @Test
+    public void testGetFlagsForSpecialization() {
+        final Flag flagBase = new Flag("prop", "red", null, null, null, null, null, null);
+        final Flag flagSpecialization = new Flag("prop", "blue", null, null, null, null, null, null);
+        final FilterUtils f = new FilterUtils(false,
+                ImmutableMap.<FilterKey, Action>builder()
+                        .put(new FilterKey(PLATFORM, "unix"), flagBase)
+                        .put(new FilterKey(OS, "amiga"), flagSpecialization)
+                        .build(), null, null);
+        f.setLogger(new TestUtils.TestLogger());
+
+        assertEquals(
+                Set.of(flagBase, flagSpecialization),
+                f.getFlags(new AttributesBuilder().add(OS, "amiga").add(PLATFORM, "unix").build(),
+                           new QName[][] {{PROPS, OS}}));
+    }
+
     // DITA 1.3
 
     @Test