Subject: Re: [xsl] flat list of contents and for-each-group From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Thu, 20 Aug 2009 13:22:49 +0200 |
my input xml file looks like this:[snip]
<book> <title>SomeTitle</title> <description>SomeDescription</description> <b_part><level_name>Chapter I: Title of Chapter I</level_name></b_part> <b_part><level_name>Section 1: Title of section 1</level_name></b_part> <b_part><level_name>Part 1: Title of Part 1</level_name></b_part> <b_part><level_name>Part 2: Title of Part 2</level_name></b_part> <b_part><level_name>Part n: Title of Part n </level_name></b_part> <b_part><level_name>Section 2: Title of Part 2</level_name></b_part> <b_part><level_name>Part 1: Title of Part 1</level_name></b_part> <b_part><level_name>Part n: Title of Part n</level_name></b_part> <b_part><level_name>Chapter II: Title of Chapter II</level_name></b_part> <b_part><level_name>A) Title of Section A</level_name></b_part> <b_part><level_name>A/1 Title of Part 1</level_name></b_part> <b_part><level_name>A/n Title of Part n</level_name></b_part> <b_part><level_name>B) Title of Section A</level_name></b_part> <b_part><level_name>B/1 Title of Part 1</level_name></b_part> <b_part><level_name>B/n Title of Part n</level_name></b_part> </book>
desired output:
<book> <title>Some title</title>
<toc> <p>paragraph</p> <chapter><title>Chapter I: Title of Chapter I</title> <section><title>Section 1: Title of Section 1</title> <part><title>Part 1: Title of Part 1</title></part> <part><title>Part 2: Title of Part 2</title></part> <part><title>Part n: Title of Part n</title></part> </section> <section><title>Section 2: Title of Section 2</title></section> <part><title>Part 1: Title of Part 1</title></part> <part><title>Part n: Title of Part n</title></part> </chapter> <chapter><title>Chapter II: Title of Chapter II</title> <section><title>A) Title of Section A</title> <part><title>A/1 Title of Part 1</title></part> <part><title>A/n Title of Part n </title></part> </section> <section><title>B) Title of Section B</title> <part><title>B/1 Title of Part 1</title></part> <part><title>B/n Title of Part n </title></part> </section> </chapter> </toc>> </book>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/2009/mf" exclude-result-prefixes="xs mf" version="2.0">
<xsl:output indent="yes"/> <xsl:strip-space elements="*"/>
<xsl:template match="b_part"> <part> <title><xsl:value-of select="level_name"/></title> </part> </xsl:template>
<book> <title>SomeTitle</title> <toc> <p>Table of contents</p> <chapter> <title>Chapter I: Title of Chapter I</title> <section> <title>Section 1: Title of section 1</title> <part> <title>Part 1: Title of Part 1</title> </part> <part> <title>Part 2: Title of Part 2</title> </part> <part> <title>Part n: Title of Part n </title> </part> </section> <section> <title>Section 2: Title of Part 2</title> <part> <title>Part 1: Title of Part 1</title> </part> <part> <title>Part n: Title of Part n</title> </part> </section> </chapter> <chapter> <title>Chapter II: Title of Chapter II</title> <section> <title>A) Title of Section A</title> <part> <title>A/1 Title of Part 1</title> </part> <part> <title>A/n Title of Part n</title> </part> </section> <section> <title>B) Title of Section A</title> <part> <title>B/1 Title of Part 1</title> </part> <part> <title>B/n Title of Part n</title> </part> </section> </chapter> </toc> </book>
Martin Honnen http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] flat list of contents and for, Stanislav Pejša | Thread | Re: [xsl] flat list of contents and, Stanislav Pejša |
Re: [xsl] Avoiding multiple "apply-, Andrew Welch | Date | Re: [xsl] Avoiding multiple "apply-, Michael Schäfer |
Month |