Re: [xsl] Building Subsections in a Chapter

Subject: Re: [xsl] Building Subsections in a Chapter
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Mon, 3 Nov 2003 19:26:09 -0800 (PST)
Please try the following 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" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:template match="/body">
  <body>
     <xsl:copy-of select="chapter"/>
       <xsl:for-each select="p">
	 <xsl:if test="substring(span, 1, 1) =
substring(preceding-sibling::p[1]/span, 1, 1)">
	   <subsection>
	     <title>
	       <xsl:value-of select="span[1]"/>
	     </title>
	     <para>
	        <xsl:value-of select="span[2]"/>
	     </para>
	   </subsection>
	</xsl:if>
	<xsl:if test="not( substring(span, 1, 1) =
substring(preceding-sibling::p[1]/span, 1, 1) )">
	   <title>
	      <xsl:value-of select="span[1]"/>
           </title>
	   <para>
	      <xsl:value-of select="span[2]"/>
	   </para>
	</xsl:if>
     </xsl:for-each>
  </body>
</xsl:template>

</xsl:stylesheet>

Hope, I understood the problem correctly

Regards,
Mukul

--- Jason Clark <JaClark@xxxxxxxxxxxxxxxxxx> wrote:
> Hello All,
> 
> I am attempting to transform the below XML document
> (CHAPTER OF A BOOK) into
> my preferred output below.  I'm having problems
> generating the subsections.
> The subsections can be 1 to N nested.  Could someone
> help with an approach
> or point me to some resources that have something
> like this.  Thanks in
> advance.
> 
> 
> SOURCE DOCUMENT:
> <body>
>  <chapter></chapter>
>   <p>
>    <span>2.1 Introduction</span>
>    <span>Content</span>
>   </p>
>   <p>
>     <span>2.1.1 My Book</span>
>     <span>Content</span>	
>   </p>
> </body>
> 
> OUTPUT I WOULD LIKE:
> <body>
>   <chapter></chapter>
>     <section>
>       <title>2.1 Introduction</title>
>       <para>Content</para>
>        <subsection>
>          <title>2.1.1 MyBook</title>
>           <para>Content</para>
>        </subsection>
>      </section>
> </body>
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread