[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

For-each-group group-starting-with drops text between

Subject: For-each-group group-starting-with drops text between inline elements
From: "Terry Ofner tdofner@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 3 Sep 2020 15:20:12 -0000
 For-each-group group-starting-with drops text between
I have a document with the following structure:
    <div>
        <p class="passage">
            <span class="itemNum">(1)</span>First <b>sentence</b> of the
passage. <span class="itemNum">(2)</span> Second sentence of the passage.
<span class="itemNum">(3)</span> Third sentence of the passage.
        </p>
    </div>

    I need to chunk this into separte items:

    <div class="passage_set">
        <p class="item" itemNum="(1)"><b>(1)</b> First <b>sentence</b> of the
passage.</p>
        <p class="item" itemNum="(2)"><b>(2)</b> Second sentence of the
passage.</p>
        <p class="item" itemNum="(3)"><b>(3)</b> Third sentence of the
passage.</p>
    </div>

    If there were no nodes in the text between spans, I could use tokenize,
which I do on such occasions.
    With sets such as the one above, I have been trying to use for-each-group.
But I am unable to capture the text between the span elements.
    Here is the relevant section of my current stylesheet (3.0 Saxon-PE
9.8.0.12):

    <xsl:variable name="passage_raw">
        <div class="passage_set">
            <xsl:for-each-group select="div/p[@class='passage']/*"
group-starting-with="span">
                <xsl:text>&#10;</xsl:text>
                <p class="item">
                    <xsl:attribute name="itemNum">
                        <xsl:value-of select="current-group()[1]"/>
                    </xsl:attribute>
                    <xsl:copy-of select="current-group()"/>
                </p>
            </xsl:for-each-group>
        </div>
    </xsl:variable>

    Here is the output:

    <div class="passage_set">
        <p class="item" itemNum="(1)"><span
class="itemNum">(1)</span><b>sentence</b></p>
        <p class="item" itemNum="(2)"><span class="itemNum">(2)</span></p>
        <p class="item" itemNum="(3)"><span class="itemNum">(3)</span></p>
    </div>

    I feel like I am close.
    Is there any way to capture the text following the span using grouping or
any other method available in 3.0?

Any help would be much appreciated.

Terry

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.