通过stackoverflow搜索,我找到了使用允许不区分大小写搜索的xpath的解决方案。我最近对架构进行了一些更改,当我返回搜索时,使用这种方法时一无所获。这是我的架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="system">
<xs:complexType>
<xs:sequence>
<xs:element ref="pData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pData">
<xs:complexType>
<xs:sequence>
<xs:element ref="pNum"/>
<xs:element ref="sData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pNum" type="xs:integer"/>
<xs:element name="sData">
<xs:complexType>
<xs:sequence>
<xs:element ref="sNum"/>
<xs:element maxOccurs="unbounded" ref="hData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sNum" type="xs:NMTOKEN"/>
<xs:element name="hData">
<xs:complexType>
<xs:sequence>
<xs:element ref="hTitle"/>
<xs:element ref="bData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hTitle" type="xs:string"/>
<xs:element name="bData">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="sitData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sitData" >
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="sitTitle"/>
<xs:element minOccurs="0" ref="sitInfo"/>
<xs:choice>
<xs:element ref="bothColumn"/>
<xs:sequence>
<xs:element ref="leftColumn"/>
<xs:element ref="rightColumn"/>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sitTitle" type="xs:string"/>
<xs:element name="sitInfo" type="xs:string"/>
<xs:element name="bothColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="bothTitle"/>
<xs:element ref="bothInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="bothTitle" type="xs:string"/>
<xs:element name="bothInfo" type="xs:string"/>
<xs:element name="leftColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="leftTitle"/>
<xs:element ref="leftInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="leftTitle" type="xs:string"/>
<xs:element name="leftInfo" type="xs:string"/>
<xs:element name="rightColumn">
<xs:complexType>
<xs:sequence>
<xs:element ref="rightTitle"/>
<xs:element ref="rightInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rightTitle" type="xs:string"/>
<xs:element name="rightInfo" type="xs:string"/>
</xs:schema>
所以我最初的搜索是:
return $doc/system/pData/sData/hData/bData/sitData[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),$searchTerm)]
所以当我搜索一个术语说“系统”时会出现我的问题,当我知道那里存在数据时,什么都不会出现,但是如果我搜索“系统”,所有版本的系统都会返回。我似乎找不到其他人遇到这个问题,虽然搜索仍然对所有小写字母不区分大小写,但我很困惑,想了解我的 xpath 搜索现在发生了什么。我正在为这些 xpath 调用使用 marklogic。这是一个适合此架构的示例 xml:
<system>
<pData>
<pNumber>908957303</pNumber>
<sData>
<sNumber>12345</sNumber>
<hData>
<hTitle>What to expect</hTitle>
<bData>
<sitData>
<sitTitle>A whole lot of fun</sitTitle>
<sitInfo> defined fun</sitInfo>
<leftColumn>
<leftTitle>to the left</leftTitle>
<leftInfo> all your clothes </leftInfo>
</leftColumn>
<rightColumn>
<rightTitle>to the right</rightTitle>
<rightInfo> right hand turns </rightInfo>
</rightColumn>
</sitData>
<sitData>
<sitTitle>we out here</sitTitle>
<sitInfo> doing this is painful </sitInfo>
<bothColumn>
<bothTitle>2001 was a good year</bothTitle>
<bothInfo>but it did have some downfalls</bothInfo>
</bothColumn>
</sitData>
</bData>
</hData>
<hData>
<hTitle>What to expect</hTitle>
<bData>
<sitData>
<sitTitle>A whole lot of fun</sitTitle>
<sitInfo> defined fun</sitInfo>
<leftColumn>
<leftTitle>to the left</leftTitle>
<leftInfo> all your clothes </leftInfo>
</leftColumn>
<rightColumn>
<rightTitle>to the right</rightTitle>
<rightInfo> right hand turns </rightInfo>
</rightColumn>
</sitData>
<sitData>
<sitTitle>we out here</sitTitle>
<sitInfo> doing this is painful </sitInfo>
<bothColumn>
<bothTitle>2001 was a good year</bothTitle>
<bothInfo>but it did have some downfalls</bothInfo>
</bothColumn>
</sitData>
</bData>
</hData>
</sData>
</pData>
</system>