How can I use the Highlight function to Style searched words

I tested successfully Highlight function of Xquery, But I cannot display a friendly Styled Page with it.

I want to change colors of the marked words.
My difficult is in use processing-instruction to generate HTML style tags in the XSL.

There is any tip to work with this command?

The file attached contains the XML, XSL and HTML that I do.

I use the query:

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
declare namespace ino="http://namespaces.softwareag.com/tamino/response2"
for $a in input()/documento/secoes/secao//linha
let $ref := tf:createNearTextReference($a, 5 , “contrabando”, “armas”)
where $ref
return { tf:highlight($a, $ref, “DESTAQUE”) }

It results the following XML:


<xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>


3. Quanto
SAG_XSL.zip (2.84 KB)

Your output.html file suggests that the processing instructions have been matched correctly. The only problem I can see seems to be the trailing whitespace in the attribute - I don’t know what the browser will do with this, but it’s untidy. It’s there because you put it there: change the code

<xsl:element name=“img”>
<xsl:attribute name=“src”>xyz.gif
</xsl:attribute>
</xsl:element>

to

<xsl:element name=“img”>
<xsl:attribute name=“src”>xyz.gif</xsl:attribute>
</xsl:element>

or more simply, to



Michael Kay

Thanks for your reply but let me tell you that my real problem is to substitute those images located before and after the selected text by HTML tags that will display the text in a special patern (colored or highlighted). Can you help me with that?

So what you actually want is to replace:

<?DESTAQUE + 1?>
armas
<?DESTAQUE - 1?>

by

armas

Is this right?

You need to think of this in terms of the tree structure you are creating, not the tags. (You need to create one element, not two tags, and creating an element is an atomic operation).

Try this:

<xsl:template match=“text()[preceding-sibling::processing-instruction(‘DESTAQUE’)
[startswith(., ‘+’)]]”>
<xsl:value-of select="."/>
</xsl:template>

This matches the text node that follows the processing instruction, and outputs the element node.

Michael Kay

Yes, I will think in this way.

This is a very good text function.

Thanks.