Subject: Re: [xsl] Trouble digesting grouping From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Fri, 06 Nov 2009 15:04:43 +0100 |
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.
I need to eliminate the parent <para > completely, output the <table> intact, but grab the <graphic> elements, create a single <figure>, then a <subfig> wrapper element for each <graphic>. Then output the structures interspersed with the tables. I can't seem to separate the tables and figures. What I'm ending up with is a single <figure> with all the <subfig>, then the tables.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<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>
<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>
<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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Trouble digesting grouping, Flanders, Charles E | Thread | [xsl] Adding a clickable URL to XSL, Anonymous Anonymous |
[xsl] Trouble digesting grouping, Flanders, Charles E | Date | [xsl] Adding a clickable URL to XSL, Anonymous Anonymous |
Month |