-1

From searching through stackoverflow I found a solution to using xpath that allows case-insensitive search. I recently made some changes to the schema and when I returned to my search I found nothing when using this approach. Here is my schema:

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

So my original search would be:

return $doc/system/pData/sData/hData/bData/sitData[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),$searchTerm)]

so my problem occurs when I search a term say "System", nothing would come up when I know there exists data in there, but if I search "system" all versions of system comes back. I couldn't seem to find someone else with this issue and while the search still does case insensitive with all lower case I'm perplexed and want to understand what is going on with my xpath search now. I'm utilizing marklogic for these xpath calls. here is a sample xml that would fit this schema:

<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>
Joshhw
  • 202
  • 2
  • 14
  • Post a [mcve] that illustrates the problem. Without seeing the XML, we cannot verify the problem. – kjhughes Mar 22 '17 at 15:21
  • @kjhughes done. – Joshhw Mar 22 '17 at 18:10
  • Cannot verify. Plugging `'System'` in for `$searchTerm` selects nothing as it should because that string does not exist in your XML, regardless of case. Plugging `'a whole' finds two `sitData` that contain that string, regardless of case, as it should. **Your problem cannot be verified with what you've posted.** – kjhughes Mar 22 '17 at 19:35
  • @kjhughes what about 'A whole' does that result in anything on your end. Also my example was just an example, the point is that when a capitalized letter is involved that the search finds nothing. – Joshhw Mar 23 '17 at 13:58
  • `A whole` works too.. The point is that your XPath is succeeding to select regardless of case. "Just an example" doesn't help; we need to see an example that truly fails before we can help it not fail -- that's a key point of a [mcve]. – kjhughes Mar 23 '17 at 14:04

1 Answers1

3

You added MarkLogic as a tag, so if you're using MarkLogic you can leverage its text functions designed for things like this:

let $doc := ...
let $q := cts:word-query($searchTerm, "case-insensitive")
return $doc//sitData[cts:contains(., $q)]

This assumes you want the match to be on word boundaries. If you really want "foo" to match "food" then you can use wildcards.

hunterhacker
  • 6,378
  • 1
  • 14
  • 11