[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: doubt

Subject: Re: doubt
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Thu, 07 Apr 2005 14:45:38 +0000
mgif
Uma (and jithendar),

While I haven't tested the solution jithendar presented (below), I'd suggest going with the route pointed out by Michael Kay in a prior post. While the solution below may work, it is specific to constrained values of "correctid", whereas Kay's tip is not.

Also, the solution below contains extraneous templates,

<xsl:template match="*|@*|comment()|processing-instruction()|text()">

for instance, that in some sense unnecessarily duplicates an XSLT processor's innate behavior.


--A



From: jithendarl <jithul@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  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



_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.