Highlight text based on reference descriptions.
tf:highlight(node $node, node $description, string $markerString) => node*
The function tf:highlight
is specific to Tamino. It takes a
sequence of nodes, a sequence of reference descriptions and a marker string as
arguments and returns $node
along with any text or nodes, for
which a reference description has been created, as enclosed between processing
instructions (PIs).
The PIs are used to mark the highlighted text. They have the following
format: The PI target is always $markerString
. It is followed by
either "+" or "-",
indicating start and end of the highlighted token. The subsequent number is the
current number of highlights in the result document.
If $markerString
is empty, the string
"Tamino-Highlighting" is used.
$node |
node in which the search takes place |
---|---|
$description |
a reference description |
$markerString |
a string value |
In the patient sample data, there is a remarks
element for the patient Bloggs that reads: "Patient is responding
to treatment. Dr. Shamir.". This remark should serve as example
text here.
Highlight book reviews using the word "discussion":
for $a in input()/reviews/entry let $ref := tf:createTextReference($a/review, "discussion") return tf:highlight($a, $ref, "REV_DISC")
This is the resulting document:
<entry> <title>Data on the Web</title> <price>34.95</price> <review>A very good <?REV_DISC + 1 ?>discussion<?REV_DISC - 1 ?> of semi-structured database systems and XML.</review> </entry> <entry> <title>Advanced Programming in the Unix environment</title> <price>65.95</price> <review>A clear and detailed <?REV_DISC + 2 ?>discussion<?REV_DISC - 2 ?> of UNIX programming.</review> </entry> <entry> <title>TCP/IP Illustrated</title> <price>65.95</price> <review>One of the best books on TCP/IP.</review> </entry>
Note that all entry
nodes are returned, although only for
the first two carry highlighted text. If only nodes with highlighted text
should be returned, simply add a where
clause checking the Boolean
return value of the reference creator function:
for $a in input()/reviews/entry let $ref := tf:createTextReference($a/review, "discussion") where $ref return tf:highlight($a, $ref, "REV_DISC")
The following construct(s) refer to this construct: