RE: [xsl] Glossary Help

Subject: RE: [xsl] Glossary Help
From: "Shailesh Shinde" <shailesh@xxxxxxxxxxxx>
Date: Mon, 31 Jul 2006 18:30:30 +0530
Hi,

The problem is there are more than three <division type="appendix">. 

When transforming with the below xsl code, if it finds "<b>AC</b>" it
changes <b> tag with glossary tag in other divisions of type appendix also. 
The select values match with other contents where division type is appendix
.

			<xsl:apply-templates select="p[not(text())]/i/b"/>
			<xsl:apply-templates select="p[text()]/i/b"/>
			<xsl:apply-templates select="p[not(text())]/b"/>
			<xsl:apply-templates select="p[text()]/b"/>


I have to change only <division type="appendix"> in which there are many
<topics> with titles as Glossary, A, B, C, D....and so on. For which I am
getting proper output which is send by you in mail thread.

So, How to avoid the changes which are happening in other divisions
type="Appendix"?

Xsl:
<?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" indent="yes"/>
	<xsl:preserve-space elements="*"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<!--<xsl:template match="*">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>-->
	
	<xsl:template match="division[@type='appendix']">
		<division>
			<xsl:copy-of select="@*"/>
			<xsl:for-each select="topic">
			<xsl:if test="./title='Glossary'">
				<topic>
					<xsl:copy-of select="@*"/>
					<xsl:copy-of select="title"/>
					<xsl:apply-templates
select="body[ancestor::division[@type='appendix']]"/>
				</topic>
				</xsl:if>
			</xsl:for-each>
			<xsl:apply-templates/> 
		</division>
	</xsl:template>
	<xsl:template match="body[ancestor::division[@type='appendix']]">
		<glossarylist>
			<xsl:apply-templates select="p[not(text())]/i/b"/>
			<xsl:apply-templates select="p[text()]/i/b"/>
			<xsl:apply-templates select="p[not(text())]/b"/>
			<xsl:apply-templates select="p[text()]/b"/>
		</glossarylist>
		<xsl:apply-templates/> 
	</xsl:template>
	<xsl:template match="p[not(text())]/i/b">
		<glossarydiv>
			<xsl:value-of select="."/>
		</glossarydiv>
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="p[text()]/i/b">
		<glossaryentry>
			<glossaryterm>
				<xsl:value-of select="."/>
			</glossaryterm>
			<glossarydef>
				<xsl:value-of select="../../text()"/>
			</glossarydef>
		</glossaryentry>
	</xsl:template>
	<xsl:template match="p[not(text())]/b">
		<glossarydiv>
			<xsl:value-of select="."/>
		</glossarydiv>
			</xsl:template>
	<xsl:template match="p[text()]/b">
		<glossaryentry>
			<glossaryterm>
				<xsl:value-of select="."/>
			</glossaryterm>
			<glossarydef>
				<xsl:value-of select="../text()"/>
			</glossarydef>
		</glossaryentry>
	</xsl:template>
	</xsl:stylesheet>


The xml structure like...

- <book>
	+ <prolog>
	+ <disclaimers>
	+ <division type="preface">
	+ <division type="general">
	+ <division type="chapter">
	+ <division type="chapter">
	+ <division type="chapter">
	+ <division type="chapter">
	+ <division type="chapter">
- <division type="appendix">
	-<topic id="Blank114">
		<title>Specifications</title>
	+ <body>
	- <topic id="Blank115">
		<title>Physical Dimensions</title>
	+ <body>
	</topic>
- <division type="appendix">  --------------------------------->>> This
division only needs
glossary Updates. 	
	-<topic id="crefmrk692">
		<title>Glossary</title>
<body>
<p>The terms in this glossary cover topics related to this manual. Alternate
naming is included for reference.</p>
<p><i><b>Abbreviations</b></i></p>
<p><i><b>AC:</b></i>  alternating current</p>
<p><i><b>AGP:</b></i>  accelerated graphics port</p>
<p><i><b>ANSI: </b></i> American National Standards Institute</p>
<p><i><b>APM:</b></i>  advanced power manager</p>
</body>
	</topic>
	-<topic id="Blank212">
		<title>A</title>
		<body>
<p><b>AccuPoint: </b> A pointing device integrated into the TOSHIBA computer
keyboard.</p>
<p><b>adaptor:  </b>A device that provides an interface between two
dissimilar electronic devices. For example, the AC adaptor modifies the
power from a wall outlet for use by the computer. This term also refers to
the add-in circuit cards that control external devices, such as video
monitors and magnetic tape devices. </p>
<p><b>allocate: </b> To assign a space or function for a specific
task.</p></body>
	</topic>
	-<topic id="Blank213">
		<title>B</title>
		Same as above
	</topic>

Topic...goes on with titles A, B, C, D..
</division>
</book>

--
Shailesh

-----Original Message-----
From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx] 
Sent: Monday, July 31, 2006 5:34 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Glossary Help

Can you please post the stylesheet you have tried? It will be helpful
if you can post your input XML, the output you desire, and tell us
about the transformation rules.

Sorry, I seem to have lost the requirements of your problem.

On 7/31/06, Shailesh Shinde <shailesh@xxxxxxxxxxxx> wrote:
> Hi,
>
> The glossary xsl code also changing the elements from other topic which
are
> not under division type="appendix". How to avoid such types of unwanted
> changes?
>
> --
> Shailesh

-- 
Regards,
Mukul Gandhi

http://gandhimukul.tripod.com

Current Thread