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

Re: doubt

Subject: Re: doubt
From: T UmaShankari <umashankari@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Apr 2005 17:09:19 +0530 (IST)
umashankari
Hello,

My doubt is, Is is possible that we can retrieve one particular tag value according to the correctid even though the tag has the same name ?

Regards,
Uma
On Thu, 7 Apr 2005, jithendarl wrote:

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



-- -- A BEST FRIEND is like a four leaf clover, HARD TO FIND and LUCKY TO HAVE.

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.