Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Highlight words?

From: "Julius Mong" <jxm96c@-------.--->
To: NULL
Date: 5/2/2006 5:41:00 PM

Dear all,

I am trying to search and highlight words in XML content displayed as HTML 
using XSLT. I have got the search bit using javascript and dom, and am at 
the moment successfully putting <font> tags around matches when I'm writing 
the results out, by grabbing document.body using dom. However Firefox 
doesn't like it and it is a known bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=325835

I gather that I cannot wait for Firefox to get its act right, so I am 
wondering if there might be an XSLT way to do similar? Pretty much I have 
the search terms fed into a javascript function that does the XSL 
transformation and displays the HTML with the matched keywords highlighted 
using <font color...>. The HTML is generated by XSLT on the fly and Firefox 
won't find document.body this way, if you save the result of the XSLT to a 
file hten load it back in Firefox will see its document.body, however a bug 
exists there it cannot be done at this moment...

What I'm asking is then, I need a way to give the XSLT the keywords to match 
and it'd find them and put <font> tags around each of them when displaying 
them. I currently have :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="no" 
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
 <xsl:attribute-set name="imgAttrs">
  <xsl:attribute name="src">page/<xsl:value-of 
select="@Href"/></xsl:attribute>
 </xsl:attribute-set>
 <xsl:template match="/">
  <html>
   <head>
    <link rel="stylesheet" href="style/template.css" type="text/css" />
   </head>
   <body id="mainBody" style="margin:25px;">
    <xsl:for-each select="//hl1">
     <h3>
      <xsl:copy-of select="."/>
     </h3>
    </xsl:for-each>
    <xsl:for-each select="//body.content/block">
     <p>
      <xsl:copy-of select="."/>
     </p>
    </xsl:for-each>
    <xsl:for-each select="//ContentItem[substring(@Href, 
string-length(@Href) - 3) = '.jpg']">
     <p>
      <xsl:element name="img" use-attribute-sets="imgAttrs"/>
     </p>
    </xsl:for-each>
 <xsl:for-each match="classes">
  <B><xsl:copy-of select="." /></B>
 </xsl:for-each>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

As you can see I'm showing things in a specific order, what I need is for 
each of these for-each results to be matched against the keywords so any 
matches will be transformed into as highlighted.

I'm no expert in XSLT, I know just enough to get by, so if anyone could give 
me some code samples that'd be greatly appreciated... on the other hand if 
anyone knows a way round the Firefox bug please also let me know ...

Many thanks!

Julius





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent