Re: [xsl] Omit TEIForm and capture attributes of current node

Subject: Re: [xsl] Omit TEIForm and capture attributes of current node
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Sep 2008 11:57:13 -0400
J.S.,

At 01:31 AM 9/25/2008, you wrote:
XSL
<xsl:template match="p">
<xsl:for-each-group select="node()" group-adjacent="self::list self::figure[@id]">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:apply-templates select="self::*"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@rend">
<p class="{@rend}">
<xsl:copy-of select="current-group()"/>
</p>
</xsl:if>
<xsl:if test="not(@rend)">
<p><xsl:copy-of select="current-group()"/></p>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>

A couple of problems here:


* Starting from the context inside for-each-group, "@rend" will not select the @rend attribute from the matched p element. Rather, the path would be "../@rend" or "parent::p/@rend". (Also there's a typo in the group-adjacent expression.)

* The group-adjacent expression isn't going to work. You need an expression that will return a single atomic value for each node in the group. Presumably, the expression you want will give one value for lists and figures with IDs (putting adjacent ones into groups), another value for all other nodes (putting adjacent ones into groups).

Then too, other improvements are also possible.

<xsl:template match="p">
<xsl:variable name="p" select="."/>
<xsl:for-each-group select="node()" group-adjacent="exists(self::list | self::figure[@id])">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:apply-templates select="current-group()"/>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:copy-of select="$p/@rend"/>
<xsl:copy-of select="current-group()"/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>


The instruction <xsl:copy-of select="$p/@rend"/> will copy any @rend attribute on the p, but it will not create @rend attributes where there are none. (The variable here is only to make it clearer what is going on: "../@rend" would also work.)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread