Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2009, 04:11 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default Display keyword in different color in html

Hi,

We're eager to know that is it possible to find specific word ("Ordinance" in this case) in the footnote element in xml file and using xslt apply color in html.

Input:
Code:
<?xml version="1.0"?>
<root>
    <para>This is para
        <footnote xtra="winding up of trading">1. The first Companies Ordinance having force in the territories which eventually</footnote>
        <footnote>2. The ..territories which eventually</footnote>
        <footnote xtra="winding up of trading">3. The first Companies having force in the territories which eventually</footnote>
        <footnote xtra="winding up of trading">4. The first Companies having force in the territories which eventually</footnote>
    </para>
</root>
We need to apply the color to differentiate the keywords in the output file.

Please guide..

Thanks
 
Old October 31st, 2009, 07:12 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you want to use XSLT 2.0 or 1.0? With 2.0 you can use xsl:analyze-string e.g.
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xsd"
  version="2.0">
  
  <xsl:param name="term" as="xsd:string" select="'Ordinance'"/>
  <xsl:param name="col" as="xsd:string" select="'red'"/>
  
  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="footnote">
    <div>
      <xsl:variable name="pattern"
                    as="xsd:string"
                    select="concat('(^|\s+|[,.!?])(', $term, ')(\s+|[,.!?]|$)')"/>
      <xsl:analyze-string select="." regex="{$pattern}">
        <xsl:matching-substring>
          <xsl:value-of select="regex-group(1)"/>
          <span style="color: red;">
            <xsl:value-of select="regex-group(2)"/>
          </span>
          <xsl:value-of select="regex-group(3)"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </div>
  </xsl:template>

</xsl:stylesheet>
would output the 'footnote' elements as
Code:
<div>1. The first Companies <span style="color: red;">Ordinance</span> having force in the territories which eventually
</div>

<div>2. The ..territories which eventually</div>

<div>3. The first Companies having force in the territories which eventually</div>

<div>4. The first Companies having force in the territories which eventually</div>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
rangeshram (November 2nd, 2009)
 
Old November 3rd, 2009, 05:41 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default

Dear Martin,

When uses the above xslt it shows the below error....
Code:
Description: Could not find function: regex-group
It would be really great if you solve this at earliest.

Thanks in advance..
 
Old November 3rd, 2009, 05:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>
Could not find function: regex-group
That means you're trying to run 2.0 code with a 1.0 XSLT processor.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
rangeshram (November 3rd, 2009)
 
Old November 3rd, 2009, 06:46 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default

Thanks Mr. Michael, I have changed the processor to Saxon and it works as our expected level ..

Cheers





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display attribute and particular string in different color rangeshram XSLT 1 October 30th, 2009 06:49 PM
How to change the color of selected row of an HTML bhavna HTML Code Clinic 4 February 11th, 2007 09:22 PM
how to display color palette swati_joshi ASP.NET 1.0 and 1.1 Basics 0 March 28th, 2006 04:32 AM
display different color in loop mateenmohd Classic ASP Basics 2 June 16th, 2004 06:40 AM
printing color in html tables Fletcher HTML Code Clinic 2 August 18th, 2003 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.