RE: [xsl] How to do this in xsl

Subject: RE: [xsl] How to do this in xsl
From: cknell@xxxxxxxxxx
Date: Sun, 27 Mar 2005 08:57:29 -0500
You haven't shown enough of your stylesheet to tell us why it isn't working.
You've haven't told us what type of output you are trying to produce, but since you speak of displaying, I'm going to assume that you want HTML output.

Here is a stylesheet that produces what I think you want. Since you didn't specify what the root element of your document is or what element might be the parent of <opt>, I took the liberty of creating a root element called <doc> and made the <opt> elements children of it.

Please note, use the "//" in your XPath only when you have a really, really, really good reason to do so. It mostly leads to poor performance and confusion. There must be a beginning tutorial on the web somewhere that uses it in an example that every beginner reads.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html" indent="yes" encoding="UTF-8" />

  <xsl:template match="/">
     <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="doc">
     <html>
        <head></head>
        <body>
        <xsl:apply-templates />
        </body>
     </html>
  </xsl:template>

  <xsl:template match="opt">
     <div>
        <span><font color="black"><xsl:value-of select="substring-before(.,'|')" /></font></span>
        <span><font color="red"><xsl:value-of select="substring-before(substring-after(.,'|'),'\')" /></font></span>
        <span><font color="black"><xsl:value-of select="substring-after(.,'\')" /></font></span>
     </div>
  </xsl:template>

</xsl:stylesheet>
--
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     T UmaShankari <umashankari@xxxxxxxxxxxxxxxxxxxx>
Sent:     Sun, 27 Mar 2005 11:22:55 +0530 (IST)
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  [xsl] How to do this in xsl



Hello,

  I am new to this..
I have a set of statements like this..

<opt mgif1="hai" mgif="" voiceover="" >Rani Lakshmi Bai |test1\ Nana Saheb</opt>
<opt mgif1="" mgif="" voiceover="" >Nana Saheb |test2\ Maruthu Brothers</opt>
<opt mgif1="" mgif="" voiceover="" >Maruthu Brothers |test3\ Tantia Tope</opt>


I need to display the contents which is inside the |to\ in different color. i have used this code for doing that..

<xsl:template match="//opt">
<font color="black">
<xsl:variable name="stringfirst">
<xsl:value-of select="substring-before(//opt,'|')"/>
</xsl:variable>
<xsl:value-of select="$stringfirst"/>
</font>
<font color="red">
<xsl:variable name="stringmid">
<xsl:value-of select="substring-after(substring-before(//opt,'\'),'|')" />
</xsl:variable>
<xsl:value-of select="$stringmid"/>
</font>

<font color="black">
<xsl:variable name="stringlast">
<xsl:value-of select="substring-after(//opt,'\')"/>
</xsl:variable>
<xsl:value-of select="$stringlast"/>
</font>


but it is displaying the o/p like this..


statement1 option1 statement1
statement1 option1 statement1

It is not going to the second statement. Can any one plese tell me how to do this ?

Regards,
Uma

Current Thread