Re: [xsl] xsl-grouping two different elements together

Subject: Re: [xsl] xsl-grouping two different elements together
From: gregor FELLENZ <gregor@xxxxxxxxxxxx>
Date: Tue, 16 Mar 2010 16:14:43 +0100
hey david,

tanks for the quick reply!

On 16.03.2010 16:09, David Carlisle wrote:
> It's hard sometimes to infer a general rule from a single example, but
> perhaps something like this, assuming that abs is usable as a group
> separator:

unfortunately i can't use <abs> as separator... there are around 10 other block level elements on the same level. the target structure is similar to html (<einschub typ="1"> behaves like a <div class="1"> [a german one :-/ ] ) in the source a <kapitel> is a chapter with block-level children (lists, table, ... ). therefore the group-adjacent="local-name()" is also used for grouping lists ... [fyi the whole template:

<xsl:template match="kapitel">
<xsl:element name="kapitel">
<xsl:copy-of select="@sprungziel"/>
<xsl:copy-of select="@DOI"/>
<xsl:copy-of select="@typ"/>
<xsl:copy-of select="@leseprobe"/>
<xsl:for-each-group select="*" group-adjacent="local-name()" >
<xsl:choose>
<xsl:when test="starts-with(current-grouping-key(),'einschub')">
<xsl:choose>
<xsl:when test="starts-with(local-name(following-sibling::*[1]), 'u') and not (starts-with(local-name(following-sibling::*[1]), 'u-zwischen'))">
<xsl:element name="einschub_vor">
<xsl:attribute name="typ" select='replace(local-name(), "[^\d]+", "")'/>
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="einschub">
<xsl:attribute name="typ" select='replace(local-name(), "[^\d]+", "")'/>
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="starts-with(current-grouping-key(),'liste_ungeordnet')">
<xsl:element name="liste_ungeordnet">
<xsl:attribute name="typ" select='replace(local-name(), "[^\d]+", "")'/>
<xsl:attribute name="zaehlertyp" select="@zaehlertyp"></xsl:attribute>
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:when>
<xsl:when test="starts-with(current-grouping-key(),'liste_geordnet')">
<xsl:element name="liste_geordnet">
<xsl:attribute name="typ" select='replace(local-name(), "[^\d]+", "")'/>
<xsl:attribute name="zaehlertyp" select="@zaehlertyp"></xsl:attribute>
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:when>


                    <xsl:otherwise>
                        <xsl:apply-templates select="current-group()"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each-group>
        </xsl:element>
    </xsl:template>

]

regards,
gregor

Current Thread