Test to see if text contains a string from a list of values
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 156
- Joined: Sat Feb 26, 2005 12:09 am
- Location: USA
- Contact:
Test to see if text contains a string from a list of values
Post by shudson310 »
I'm trying to create a Schematron rule that will check text nodes against a list of terms in an external document. Basically, I'm trying to see if writers included a product name directly in text instead of using a keyref in DITA.
I'm reading in my external document by:
I need a test that will check to see if the text nodes contain one of the values from
I can get an exact match using:
But that only works if the entire node matches. I want to check if the phrase is contained within a larger set of text.
Trying something like this: results in:
A sequence of more than one item is not allowed as the first argument of fn:contains() ("
", "
")
Any ideas?
I'm reading in my external document by:
Code: Select all
<sch:let name="keys"
value="document('keys-common.ditamap')"/>
Code: Select all
$keys//keyword
Code: Select all
<sch:let name="text" value="text()"/>
<sch:report id="now001"
test="$keys//keyword[normalize-space(.) =$text]"
role="error">
Trying something like this:
Code: Select all
test="$keys//keyword[contains($text, .)]"
A sequence of more than one item is not allowed as the first argument of fn:contains() ("
", "
")
Any ideas?
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
Staff Content Engineer
Site: docs.servicenow.com
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Test to see if text contains a string from a list of values
Hello Scott ,
I think that a solution can be to count the number of matched keys, then you can write also the matched keys in the assertion message. The pattern must look something like this:
Best Regards,
Octavian
I think that a solution can be to count the number of matched keys, then you can write also the matched keys in the assertion message. The pattern must look something like this:
Code: Select all
<sch:pattern>
<sch:let name="keys" value="document('keys-common.ditamap')//keyword"/>
<sch:rule context="p">
<sch:let name="text" value="text()"/>
<sch:let name="matchedKeys" value="$keys[contains($text, normalize-space(.))]"/>
<sch:report id="now001" test="count($matchedKeys) > 0" role="error">
Text contains keywords: <sch:value-of select="$matchedKeys"/>
</sch:report>
</sch:rule>
</sch:pattern>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 156
- Joined: Sat Feb 26, 2005 12:09 am
- Location: USA
- Contact:
Re: Test to see if text contains a string from a list of values
Post by shudson310 »
Unfortunately, I get this error:
A sequence of more than one item is not allowed as the first argument of fn:contains() ("Access to the ", " overview module is granted to a sp...")
A sequence of more than one item is not allowed as the first argument of fn:contains() ("Access to the ", " overview module is granted to a sp...")
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
Staff Content Engineer
Site: docs.servicenow.com
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Test to see if text contains a string from a list of values
Hello Scott,
Yes, in case there are multiple text nodes in a paragraph the "text()" function will return a sequence of text nodes. You can replace the "$text" variable with the following one:
Best Regards,
Octavian
Yes, in case there are multiple text nodes in a paragraph the "text()" function will return a sequence of text nodes. You can replace the "$text" variable with the following one:
Code: Select all
<sch:let name="text" value="."/>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service