[Home] [By Thread] [By Date] [Recent Entries]
Flanders, Charles E (US SSA) wrote:
I'm struggling with a grouping problem. I've had some success with simpler structures, but this one has me stumped. This is an XML to XML transform. This stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template> <xsl:template match="install/proc">
<xsl:apply-templates/>
</xsl:template> <xsl:template match="install/para">
<xsl:for-each-group select="*" group-adjacent="node-name(.)">
<xsl:choose>
<xsl:when test="current-grouping-key() eq QName('', 'graphic')">
<figure>
<title/>
<xsl:apply-templates select="current-group()"/>
</figure>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template> <xsl:template match="graphic">
<subfig>
<xsl:copy-of select="."/>
</subfig>
</xsl:template></xsl:stylesheet> when applied to <install>
<proc>
<step1>
<para></para>
</step1>
</proc>
<para>
<table>
All the table stuff
</table>
<graphic/>
<graphic/>
<graphic/>
<table>
All the table stuff
</table>
<graphic/>
<graphic/>
<graphic/>
</para>
</install>outputs <install> <step1>
<para/>
</step1> <table>
All the table stuff
</table>
<figure>
<title/>
<subfig>
<graphic/>
</subfig>
<subfig>
<graphic/>
</subfig>
<subfig>
<graphic/>
</subfig>
</figure>
<table>
All the table stuff
</table>
<figure>
<title/>
<subfig>
<graphic/>
</subfig>
<subfig>
<graphic/>
</subfig>
<subfig>
<graphic/>
</subfig>
</figure>
</install>
--Martin Honnen http://msmvps.com/blogs/martin_honnen/
|

Cart



