为什么此xpath与该文本节点匹配?

时间:2018-08-23 16:31:02

标签: xml xpath xpath-2.0 dita-ot

为什么来自dita-ot的xpath

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

匹配文本节点“入门”吗?

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

问候 继续

1 个答案:

答案 0 :(得分:4)

DTD可以提供默认属性值。此处理在应用任何XPath表达式之前进行。您在此处引用的DTD有点复杂,但是如果我在其上运行标识XSLT样式表(获取输入,从DTD填写任何默认值,然后将其复制出来),则预处理后的输入看起来更像(格式很浅)

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

在此步骤之后,显然<concept />元素具有包含class的{​​{1}}属性,而子元素具有包含topic/topic的{​​{1}}属性。