Determine if a string appears in the first 100 or last 100 text node characters of an html content object
Given a string of text "my search phrase", inside an htm开发者_C百科l content block, how would you determine if the string appears within the first 100 or last 100 non tag-based characters of the document? (Don't count html tags, only text nodes)
Example, this would return true...
<p>This html text block contains <b>My Search Phrase</b>, because it appears in the first 100 characters of the content.</p>
how would you determine if the string appears within the first 100 or last 100 non tag-based characters of the document?
In the absence of any definition of "non-tag-based characters, I assume these are any characters of the string value of the document: string(/)
.
Therefore:
contains(substring(/,1,100),'my search phrase')
returns true()
exactly when the first 100 characters of the string value of the document contain the string 'my search phrase'
.
Similarly:
contains(substring(/, string-length(/)-99),'my search phrase')
returns true()
exactly when the last 100 characters of the string value of the document contain the string 'my search phrase'
.
Therefore:
contains(substring(/,1,100),'my search phrase')
or
contains(substring(/, string-length(/)-99),'my search phrase')
returns true()
exactly when the first or last 100 characters of the string value of the document contain the string 'my search phrase'
.
精彩评论