Search code examples
xmlxpathxpath-2.0dita-ot

Why does this xpath match this text node?


Why does this xpath from dita-ot

"*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]

match the text node "Getting started"?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "http://docs.oasis-open.org/dita/v1.1/OS/dtd/concept.dtd">
<concept id="mobileapp_gs" rev="3">
    <title>Getting started</title>
    <conbody>        
    </conbody>
</concept>

Regards Conteh


Solution

  • The DTD can provide default attribute values. This processing happens before applying any XPath expressions. The DTD you reference here is somewhat complex, but if I run an identity XSLT stylesheet over it (take the input, fill in any defaults from the DTD, and just copy it out) the preprocessed input looks more like (lightly formatted)

    <?xml version="1.0"?>
    <concept xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
             id="mobileapp_gs"
             rev="3"
             ditaarch:DITAArchVersion="1.1"
             domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                          (topic ut-d) (topic indexing-d)"
             class="- topic/topic concept/concept ">
        <title class="- topic/title ">Getting started</title>
        <conbody class="- topic/body  concept/conbody ">        
        </conbody>
    </concept>
    

    After this step, the <concept /> element more obviously has a class attribute containing topic/topic, with a child element with a class attribute containing topic/title.