Hi All,
I have this as my input XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<topic>
<para>topic 1</para>
<subtopic>
<para>subtopic 1a</para>
</subtopic>
<subtopic>
<para>subtopic 1b</para>
</subtopic>
<subtopic>
<para>subtopic 1c</para>
</subtopic>
<subtopic>
<para>subtopic 1d</para>
</subtopic>
</topic>
<topic>
<para>topic 2</para>
</topic>
<topic>
<para>topic 3</para>
<subtopic>
<para>subtopic 3a</para>
</subtopic>
<subtopic>
<para>subtopic 3b</para>
</subtopic>
<subtopic>
<para>subtopic 3c</para>
</subtopic>
</topic>
</root>
My goal is to convert adjacent topic elements into an <ol> element and
adjacent subtopic elements into a <ul> element.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<ol>
<li>
<para>topic 1</para>
<ul>
<li>
<para>subtopic 1a</para>
</li>
<li>
<para>subtopic 1b</para>
</li>
<li>
<para>subtopic 1c</para>
</li>
<li>
<para>subtopic 1d</para>
</li>
</ul>
</li>
<li>
<para>topic 2</para>
</li>
<li>
<para>topic 3</para>
<ul>
<li>
<para>subtopic 3a</para>
</li>
<li>
<para>subtopic 3b</para>
</li>
<li>
<para>subtopic 3c</para>
</li>
</ul>
</li>
</ol>
</root>
I am using nested xsl:for-each-group constructs but I don't get the inner
<ul> elements. I think I am incorrect in my use of current-grouping-key() or
current-group() on the inner group. Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/root">
<root>
<xsl:for-each-group select="*" group-adjacent="if(self::topic)
then 1 else 0">
<xsl:choose>
<xsl:when test="current-grouping-key()=1">
<ol>
<xsl:for-each-group select="current-group()"
group-adjacent="if(self::subtopic) then 1 else 0">
<xsl:choose>
<xsl:when
test="current-grouping-key()=1">
<ul>
<xsl:apply-templates
select="current-group()"/>
</ul>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</ol>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</root>
</xsl:template>
<xsl:template match="topic|subtopic">
<li><xsl:apply-templates/></li>
</xsl:template>
<!-- Identity transform. -->
<xsl:template match="@*|node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Rick
Rick Quatro
Carmen Publishing Inc.
rick(_at_)frameexpert(_dot_)com
585-729-6746
www.frameexpert.com/store/
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--