Subject: Re: [xsl] doubt From: "Aron Bock" <aronbock@xxxxxxxxxxx> Date: Thu, 07 Apr 2005 14:45:38 +0000 |
From: jithendarl <jithul@xxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] doubt Date: Thu, 7 Apr 2005 16:56:17 +0530
Hi, Here is a sample program that may help you how to use the conditional statements in XSLT.
INPUT:
<?xml version="1.0" encoding="UTF-8"?> <root> <question correctid="3" Qno="370" > <stmt1 mgif1="" mgif="" misc="" >Kepler's first law of planetary motion is also called </stmt1> <stmt2 mgif1="" mgif="" misc="" /> <opt mgif1="" mgif="" voiceover="" >law of periods</opt> <opt mgif1="" mgif="" voiceover="" >law of areas</opt> <opt mgif1="" mgif="" voiceover="" >law of orbits</opt> <opt mgif1="" mgif="" voiceover="" >law of distances</opt> </question> <question correctid="4" Qno="370" > <stmt1 mgif1="" mgif="" misc="" >Kepler's first law of planetary motion is also called </stmt1> <stmt2 mgif1="" mgif="" misc="" /> <opt mgif1="" mgif="" voiceover="" >law of periods</opt> <opt mgif1="" mgif="" voiceover="" >law of areas</opt> <opt mgif1="" mgif="" voiceover="" >law of orbits</opt> <opt mgif1="" mgif="" voiceover="" >law of distances</opt> </question> </root>
XSL FILE::
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates
select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:element name="{name()}">
<xsl:apply-templates select="question"/>
</xsl:element>
</xsl:template>
<xsl:template match="question">
<xsl:variable name="id" select="@correctid"/>
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:for-each select="child::*">
<xsl:if test="$id='3'">
<xsl:element name="blue">
<xsl:copy>
<xsl:apply-templates
select="*|@*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:element>
</xsl:if>
<xsl:if test="$id='4'">
<xsl:element name="red">
<xsl:copy>
<xsl:apply-templates
select="*|@*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
output file::
<?xml version="1.0" encoding="UTF-8"?> <root> <question correctid="3" Qno="370"> <blue> <stmt1 mgif1="" mgif="" misc="">Kepler's first law of planetary motion is also called </stmt1> </blue> <blue> <stmt2 mgif1="" mgif="" misc=""/> </blue> <blue> <opt mgif1="" mgif="" voiceover="">law of periods</opt> </blue> <blue> <opt mgif1="" mgif="" voiceover="">law of areas</opt> </blue> <blue> <opt mgif1="" mgif="" voiceover="">law of orbits</opt> </blue> <blue> <opt mgif1="" mgif="" voiceover="">law of distances</opt> </blue> </question> <question correctid="4" Qno="370"> <red> <stmt1 mgif1="" mgif="" misc="">Kepler's first law of planetary motion is also called </stmt1> </red> <red> <stmt2 mgif1="" mgif="" misc=""/> </red> <red> <opt mgif1="" mgif="" voiceover="">law of periods</opt> </red> <red> <opt mgif1="" mgif="" voiceover="">law of areas</opt> </red> <red> <opt mgif1="" mgif="" voiceover="">law of orbits</opt> </red> <red> <opt mgif1="" mgif="" voiceover="">law of distances</opt> </red> </question> </root>
On Apr 7, 2005 2:13 PM, T UmaShankari <umashankari@xxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> Hello,
>
> I am having the xml file in this format.
>
> <question correctid="3" Qno="370" >
> <stmt1 mgif1="" mgif="" misc="" >Kepler's first law of planetary motion is also called </stmt1>
> <stmt2 mgif1="" mgif="" misc="" />
> <opt mgif1="" mgif="" voiceover="" >law of periods</opt>
> <opt mgif1="" mgif="" voiceover="" >law of areas</opt>
> <opt mgif1="" mgif="" voiceover="" >law of orbits</opt>
> <opt mgif1="" mgif="" voiceover="" >law of distances</opt>
> </question>
>
> For example, If the correct id number value is 3 the law of orbits value
> should appear in different color. so according the correct id the color of
> the option should get changed. Is it possible to do ?
>
> Regards,
> Uma
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] doubt, T UmaShankari | Thread | Re: [xsl] doubt, Mukul Gandhi |
[xsl] get all element dom tree, 04083259 | Date | RE: [xsl] generating namespace attr, Michael Kay |
Month |