[xsl] Getting text nodes from the current-group()

Subject: [xsl] Getting text nodes from the current-group()
From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 May 2018 15:11:44 -0000
Hi,

I have input XML that is flat and I am trying to group on one of the
elements. I am able to group, but I don't know how to get the text nodes
from the group. Here is an input snippet:


<?xml version="1.0" encoding="UTF-8"?>
<div type="book" osisID="Matt" canonical="true">
    <milestone type="x-usfm-toc1" n="El Evangelio De Nuestro Seqor Jesu
Cristo Segzn San Mateo" />
    <milestone type="x-usfm-toc2" n="San Mateo" />
    <milestone type="x-usfm-toc3" n="Mat" />
    <!-- mt --><title type="main">EL EVANGELIO DE NUESTRO SEQOR JESU CRISTO
SEGZN SAN MATEO</title>
    <chapter sID="Matt.1" osisID="Matt.1" n="1" />
    <!-- cl --><milestone type="x-chapterLabel" n="CAPITULO 1" />
    <verse sID="Matt.1.1" n="1" />Libro de la generacisn de Jesu Cristo,
hijo de David, hijo de Abraham.
    <verse eID="Matt.1.1" />
    <verse sID="Matt.1.2" n="2" />Abraham engendrs a Isaac; e Isaac engendrs
a Jacob; y Jacob engendrs a Jzdas, y a sus hermanos;
    <verse eID="Matt.1.2" />
    <verse sID="Matt.1.3" n="3" />Y Jzdas engendrs de Tamar a Fares y a
Zara; y Fares engendrs a Esrom; y Esrom engendrs a Aram;
    <verse eID="Matt.1.3" />
    <verse sID="Matt.1.4" n="4" />Y Aram engendrs a Aminadab; y Aminadab
engendrs a Naassn; y Naassn engendrs a Salmsn;
    <verse eID="Matt.1.4" />
    <verse sID="Matt.1.5" n="5" />Y Salmsn engendrs de Raab a Booz; y Booz
engendrs de Rut a Obed; y Obed engendrs a Jessi;
    <verse eID="Matt.1.5" />
    <verse sID="Matt.1.6" n="6" />Y Jessi engendrs al rey David; y el rey
David engendrs a Salomsn de la <transChange type="added">que fue
mujer</transChange> de Urmas;
    <verse eID="Matt.1.6" />
</div>

My current stylesheet:

<?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 method="text"/>

    <xsl:template match="/div[@osisID='Matt']">
        <xsl:for-each-group select="*" group-starting-with="verse[@sID]">
            <xsl:apply-templates select="current-group()[self::title]"/>
            <xsl:apply-templates select="current-group()[not(self::title or
self::verse[@eID])]"/>
        </xsl:for-each-group>

    </xsl:template>

    <xsl:template match="chapter[@n]">
        <xsl:text>Capitulo </xsl:text><xsl:value-of
select="@n"/><xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="verse[@n]">
        <xsl:value-of select="@n"/><xsl:text>
</xsl:text><xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="title">
        <xsl:apply-templates/><xsl:text>&#xA;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

My output will be text; here is the current output:

EL EVANGELIO DE NUESTRO SEQOR JESU CRISTO SEGZN SAN MATEO
Capitulo 1
1
2
3
4
5
6
que fue mujer

Of course, I want the text nodes as well. A slight wrinkle is that I may
want to preserve the tagging around any children of the text nodes, like
this (verse 6):

EL EVANGELIO DE NUESTRO SEQOR JESU CRISTO SEGZN SAN MATEO
Capitulo 1
1 Libro de la generacisn de Jesu Cristo, hijo de David, hijo de Abraham.
2 Abraham engendrs a Isaac; e Isaac engendrs a Jacob; y Jacob engendrs a
Jzdas, y a sus hermanos;
3 Y Jzdas engendrs de Tamar a Fares y a Zara; y Fares engendrs a Esrom; y
Esrom engendrs a Aram;
4 Y Aram engendrs a Aminadab; y Aminadab engendrs a Naassn; y Naassn
engendrs a Salmsn;
5 Y Salmsn engendrs de Raab a Booz; y Booz engendrs de Rut a Obed; y Obed
engendrs a Jessi;
6 Y Jessi engendrs al rey David; y el rey David engendrs a Salomsn de la
<transChange type="added">que fue mujer</transChange> de Urmas;

Thank you in advance.

Rick

Rick Quatro
Carmen Publishing Inc.
rick@xxxxxxxxxxxxxxx
585-366-4017

Current Thread