RE: [xsl] Glossary Help

Subject: RE: [xsl] Glossary Help
From: "Shailesh Shinde" <shailesh@xxxxxxxxxxxx>
Date: Sat, 29 Jul 2006 18:06:33 +0530
Hi,

The exact XML structure is like below........this <division type="appendix">
only needs to update with glossary elements, also the division contains more
topics with titles A, B, C and so on.....

- <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>
	</topic>
	-<topic id="Blank212">
		<title>A</title>
	</topic>
	-<topic id="Blank213">
		<title>B</title>
	</topic>
</division>
</book>


--
shailesh

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

Don't know what is the exact XML you have. Perhaps you have a XML
something like following:

<?xml version="1.0" ?>
<divisions>
  <division>
    <x/>
    <body>
      <body-contents/>
    </body>
  </division>
  <!-- may have more division tags, as above -->
  <division type="appendix">
    <topic id="cfmrk">
      <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="Blank">
     <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>
       <p><b>alphanumeric:</b>  Keyboard characters including letters,
numbers and
other symbols, such as punctuation marks or mathematical symbols.</p>
     </body>
   </topic>
 </division>
</divisions>

To transform this to the desired XML, the stylesheet will be (I think
you want to produce glossary where division has a attribute
type="appendix"):

<?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: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">
      <topic>
        <xsl:copy-of select="@*" />
        <xsl:copy-of select="title" />
        <xsl:apply-templates select="body" />
      </topic>
    </xsl:for-each>
  </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:template>

<xsl:template match="p[not(text())]/i/b">
  <glossarydiv>
    <xsl:value-of select="." />
  </glossarydiv>
</xsl:template>

<xsl:template match="p[text()]/i/b">
  <glossaryterm>
    <xsl:value-of select="." />
  </glossaryterm>
  <glossarydef>
    <xsl:value-of select="../../text()" />
  </glossarydef>
</xsl:template>

<xsl:template match="p[not(text())]/b">
  <glossarydiv>
    <xsl:value-of select="." />
  </glossarydiv>
</xsl:template>

<xsl:template match="p[text()]/b">
  <glossaryterm>
    <xsl:value-of select="." />
  </glossaryterm>
  <glossarydef>
    <xsl:value-of select="../text()" />
  </glossarydef>
</xsl:template>

</xsl:stylesheet>

The output produced is:

<?xml version="1.0" encoding="UTF-8"?>
<divisions>
  <division>
      <x/>
      <body>
         <body-contents/>
      </body>
  </division>
  <division type="appendix">
      <topic id="cfmrk">
         <title>Glossary</title>
         <glossarylist>
            <glossarydiv>Abbreviations</glossarydiv>
            <glossaryterm>AC:</glossaryterm>
            <glossarydef>  alternating current</glossarydef>
            <glossaryterm>AGP:</glossaryterm>
            <glossarydef>  accelerated graphics port</glossarydef>
            <glossaryterm>ANSI: </glossaryterm>
            <glossarydef> American National
Standards Institute</glossarydef>
            <glossaryterm>APM:</glossaryterm>
            <glossarydef>  advanced power manager</glossarydef>
         </glossarylist>
      </topic>
      <topic id="Blank">
         <title>A</title>
         <glossarylist>
            <glossaryterm>AccuPoint: </glossaryterm>
            <glossarydef> A pointing device integrated into the TOSHIBA
computer keyboard.</glossarydef>
            <glossaryterm>adaptor:  </glossaryterm>
            <glossarydef>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. </glossarydef>
            <glossaryterm>allocate: </glossaryterm>
            <glossarydef> To assign a space or function for a specific
task.</gl
ossarydef>
            <glossaryterm>alphanumeric:</glossaryterm>
            <glossarydef>  Keyboard characters including letters, numbers
and
other symbols, such as punctuation marks or mathematical
symbols.</glossarydef>
         </glossarylist>
      </topic>
   </division>
</divisions>

If you need more help, please let us know.

Regards,
Mukul

http://gandhimukul.tripod.com

On 7/29/06, Shailesh Shinde <shailesh@xxxxxxxxxxxx> wrote:
> Hi,
>
> Yes, having other divisions also in the xml? So, needs to update only the
> part of xml where glossary needed.
>
> --
> Shailesh

Current Thread