Subject: Re: [xsl] Muenchian Method Doesn't go far enough for me From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 17 Oct 2002 08:02:19 -0400 |
I'm having some trouble with grouping.
I've moved to the Muenchian method, which makes good sense to me.
A similar problem to mine would be writing a transform to convert flat HTML sections to hiearchical sections.
In HTML, you might have:
H1 H2 H2 H3 H2 H1 H2
Let's remap it to: <test> <section> <title>H1</title> </section> <section> <title>H2</title> </section>
<xslt:key name="sections" match="section" use="title"/>
t:\ftemp>type rich.xml <html> <body> <h1>H1 title 1</h1> <p>P for H1-1</p> <h2>H2 title 1.1</h2> <p>P for H2-1.1</p> <h2>H2 title 1.2</h2> <p>P for H2-1.2</p> <h3>H3 title 1.2.1</h3> <p>P for H3-1.2.1</p> <h4>H4 title 1.2.1.1</h4> <p>P for H4-1.2.1.1</p> <h5>H5 title 1.2.1.1.1</h5> <p>P for H5-1.2.1.1.1</p> <h6>H6 title 1.2.1.1.1.1</h6> <p>P for H6-1.2.1.1.1.1</p> <h2>H2 title 1.3</h2> <p>P for H2-1.3</p> <h1>H1 title 2</h1> <p>P for H1-2</p> <h2>H2 title 2.1</h2> <p>P for H2-2.1</p> </body> </html>
t:\ftemp>type rich.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="h2s" match="h2" use="generate-id(preceding-sibling::h1[1])"/> <xsl:key name="h3s" match="h3" use="generate-id(preceding-sibling::h2[1])"/> <xsl:key name="h4s" match="h4" use="generate-id(preceding-sibling::h3[1])"/> <xsl:key name="h5s" match="h5" use="generate-id(preceding-sibling::h4[1])"/> <xsl:key name="h6s" match="h6" use="generate-id(preceding-sibling::h5[1])"/>
<xsl:template match="*" mode="next"> <xsl:if test="not( translate( local-name(.),'123456','' ) = 'h' )"> <xsl:apply-templates select="."/> <xsl:apply-templates select="following-sibling::*[1]" mode="next"/> </xsl:if> </xsl:template>
<xsl:template match="p"> <para><xsl:apply-templates/></para> </xsl:template>
t:\ftemp>type rich.out <?xml version="1.0" encoding="utf-8"?>
<test> <section> <title>H1 title 1</title> <para>P for H1-1</para> <section> <title>H2 title 1.1</title> <para>P for H2-1.1</para> </section> <section> <title>H2 title 1.2</title> <para>P for H2-1.2</para> <section> <title>H3 title 1.2.1</title> <para>P for H3-1.2.1</para> <section> <title>H4 title 1.2.1.1</title> <para>P for H4-1.2.1.1</para> <section> <title>H5 title 1.2.1.1.1</title> <para>P for H5-1.2.1.1.1</para> <section> <title>H6 title 1.2.1.1.1.1</title> <para>P for H6-1.2.1.1.1.1</para> </section> </section> </section> </section> </section> <section> <title>H2 title 1.3</title> <para>P for H2-1.3</para> </section> </section> <section> <title>H1 title 2</title> <para>P for H1-2</para> <section> <title>H2 title 2.1</title> <para>P for H2-2.1</para> </section> </section> </test>
-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Next public training: 2002-12-08,2003-02-03,06,03-03,06
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Muenchian Method Doesn't go f, Richard Lander | Thread | RE: [xsl] Muenchian Method Doesn't , DPawson |
RE: [xsl] probs with document(), James Carlyle | Date | RE: [xsl] Muenchian Method Doesn't , DPawson |
Month |