Subject: Re: [xsl] Approach for wrapping elements From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 07 Jan 2003 14:55:06 -0500 |
I have a document that is of this form:
...
The elements above or below the listitems may be different. A list may also appear more than once in a document. Can anyone provide a method for wrapping listitems as a group with <itemizedlist> to produce this result?
T:\ftemp>type pratt.xml <?xml version="1.0" encoding="iso-8859-1"?> <test> <para>Paragraph text</para> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> <para>More text</para> <para>Paragraph text</para> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> <para>More text</para> <para>Paragraph text</para> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> <para>More text</para> </test> T:\ftemp>type pratt.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node()" name="copy-this"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<xsl:template match="listitem"> <itemizedlist> <xsl:apply-templates mode="copy-adjacent" select="."/> </itemizedlist> </xsl:template>
<xsl:template mode="copy-adjacent" match="listitem"> <xsl:call-template name="copy-this"/> <xsl:apply-templates select="following-sibling::*[1][self::listitem]" mode="copy-adjacent"/> </xsl:template>
T:\ftemp>saxon pratt.xml pratt.xsl <?xml version="1.0" encoding="utf-8"?> <test>
<itemizedlist> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> </itemizedlist>
<itemizedlist> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> </itemizedlist>
<itemizedlist> <listitem>1st item</listitem> <listitem>2nd item</listitem> <listitem>3rd item</listitem> </itemizedlist>
</test> T:\ftemp>rem Done!
-- Upcoming hands-on in-depth North America: February 3- 7,2003 XSLT/XPath and XSL-FO Europe: February 17-21,2003
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 Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Approach for wrapping element, Dave Pratt | Thread | [xsl] using xsl to substitute synon, Thomas McDonald |
RE: [xsl] Number of times apply-tem, Wendell Piez | Date | [xsl] using xsl to substitute synon, Thomas McDonald |
Month |