xsl-list
[Top] [All Lists]

Re: [xsl] For-each-group group-starting-with drops text between inline elements

2020-09-03 10:37:57
Thanks Wendell and Martin. Of course. Makes sense. /node() works perfectly in 
this instance.

On Sep 3, 2020, at 11:29 AM, Wendell Piez wapiez(_at_)wendellpiez(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Terry,

Don't kick yourself, but the path in your select expression 
"div/p[@class='passage']/*" will select only elements.

To select all nodes, use "div/p[@class='passage']/node()", or for just 
elements and text (no comments or PIs, use "div/p[@class='passage']/(* | 
text())".

I can see this easily 'cause I've made this mistake dozens of times.

Cheers, Wendell


On Thu, Sep 3, 2020 at 11:20 AM Terry Ofner tdofner(_at_)gmail(_dot_)com 
<mailto:tdofner(_at_)gmail(_dot_)com> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:
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

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by 
email <applewebdata://441651FB-57C6-4AA3-BC14-21AAC64B3A82>)


-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez. <http://github.com/wendellpiez.>.. 
...gitlab.coko.foundation/wendell...
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/723745> (by 
email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>