RE: RE: [xsl] How to do this in xsl

Subject: RE: RE: [xsl] How to do this in xsl
From: cknell@xxxxxxxxxx
Date: Sun, 27 Mar 2005 09:29:45 -0500
Apologies to anyone who has an HTML email client. If that is the case, then the contents of the template that matches the <doc> element may not have displayed. Here is a version that I have encoded to display it in HTML.

<xsl:template match="doc">
 &lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      <xsl:apply-templates />
    &lt;/body&gt;
 &lt;/html&gt;
</xsl:template>
--
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     cknell@xxxxxxxxxx
Sent:     Sun, 27 Mar 2005 08:57:29 -0500
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  RE: [xsl] How to do this in xsl

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