[oXygen-user] xslt puzzle

Kalvesmaki, Joel KalvesmakiJ at doaks.org
Tue Mar 6 08:55:05 CST 2018


Lou,

Below is how I would approach it. I take into account that you want to treat the opening span specially.

Best wishes,

jk
--
Joel Kalvesmaki
Managing Editor in Byzantine Studies
Dumbarton Oaks
202 339 6435






    <xsl:template match="div[@class = 'wpvw-motto']">
        <xsl:variable name="opener" select="span[not(preceding-sibling::node())]" as="element()?"/>
        <quote>
            <xsl:apply-templates select="$opener"/>
            <xsl:for-each-group select="node() except $opener" group-ending-with="br">
                <p>
                    <xsl:apply-templates select="current-group()"/>
                </p>
            </xsl:for-each-group>
        </quote>
    </xsl:template>
    <xsl:template match="*[@class = 'cursief']">
        <hi rend="italic">
            <xsl:value-of select="."/>
        </hi>
    </xsl:template>
    <xsl:template match="br"/>



From: oXygen-user <oxygen-user-bounces at oxygenxml.com> on behalf of Lou Burnard <lou.burnard at retired.ox.ac.uk>
Date: Tuesday, March 6, 2018 at 9:21 AM
To: "oxygen-user at oxygenxml.com" <oxygen-user at oxygenxml.com>
Subject: [oXygen-user] xslt puzzle


I take the liberty of exposing my ignorance of how to use the cool grouping features of xslt on the list, in the hope that someone will take pity on me and explain what's going on here.

My input file (in the HTML namespace) contains chunks like this:

<div class="wpvw-motto"><span class="cursief">Waarde Meryan!</span>

<br/>

‘In aanmerking genomen onze gewoonlijk niet heel drukke (!) correspondentie, ...  Dus, vous voilà prévenu, le pire est fait.

<br/>

‘Weet dan ...  voet voortleven en ten slotte totaal geruïneerd! Hij, <span class="cursief">zeer</span> plotseling gestorven.... gij begrijpt mij wel!

<br/>

</div>


which I want to transform  (obviously) to something like this

<quote><hi rend="italic">Waarde Meryan!</hi>

<p>

‘In aanmerking genomen onze gewoonlijk niet heel drukke (!) correspondentie, ...  Dus, vous voilà prévenu, le pire est fait.

</p>

<p>

‘Weet dan ...  voet voortleven en ten slotte totaal geruïneerd! Hij, <hi rend="italic">zeer</hi> plotseling gestorven.... gij begrijpt mij wel!

</p>

</quote>

My stylesheet has a template for div[@class] which contains the following:

<xsl:when test="@class = 'wpvw-motto'">
<quote>
<xsl:for-each-group select="node()" group-ending-with="h:br">
<xsl:for-each select="current-group()">
<p>
<xsl:choose>
<xsl:when test="self::h:br"/>
<xsl:when test="self::h:span">
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:for-each>
</xsl:for-each-group>
</quote>
</xsl:when>

and another for span which handles the conversion to <hi>

... and this NEARLY works. But not quite. It generates

<quote><p>
<hi rend="italic">Waarde Meryan!</hi> </p>
<p>
‘In aanmerking genomen onze gewoonlijk niet heel drukke (!) correspondentie, ... Dus, vous voilà prévenu, le pire est fait.
</p>>
<p>
‘Weet dan ... voet voortleven en ten slotte totaal geruïneerd! Hij, </p>
<p><hi rend="italic">zeer</hi></p>
<p> plotseling gestorven.... gij begrijpt mij wel!
</p>
</quote>

i.e. it looks as if the current-group starts a new sequence for each h:div child, rather than for each <br/>. So I am misunderstanding something fairly fundamental about how this grouping mechanism works.

Any and all advice gratefully received!

Lou

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business, providing a safer and more useful place for your human generated data. Mimecast specializes in security, archiving and compliance. To find out more visit the Mimecast website.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.oxygenxml.com/pipermail/oxygen-user/attachments/20180306/6c01f141/attachment.html>


More information about the oXygen-user mailing list