Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an XSLT 1.0 solution:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:output method="xml" encoding="utf-8" /&gt; &lt;!-- the identity template copies everything verbatim --&gt; &lt;xsl:template match="node() | @*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node() | @*" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- this matches the first &lt;emph&gt; nodes of their kind in a row --&gt; &lt;xsl:template match="emph[not(@type = preceding-sibling::emph[1]/@type)]"&gt; &lt;xsl:variable name="elementname"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="@type='bold'"&gt;strong&lt;/xsl:when&gt; &lt;xsl:when test="@type='italic'"&gt;em&lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:if test="$elementname != ''"&gt; &lt;!-- the first preceding node with a different type is the group separator --&gt; &lt;xsl:variable name="boundary" select="generate-id(preceding-sibling::emph[@type != current()/@type][1]) " /&gt; &lt;xsl:element name="{$elementname}"&gt; &lt;!-- select all &lt;emph&gt; nodes of the row with the same type... --&gt; &lt;xsl:variable name="merge" select=". | following-sibling::emph[ @type = current()/@type and generate-id(preceding-sibling::emph[@type != current()/@type][1]) = $boundary ]" /&gt; &lt;xsl:apply-templates select="$merge" mode="text" /&gt; &lt;/xsl:element&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;!-- default: keep &lt;emph&gt; nodes out of the identity template mechanism --&gt; &lt;xsl:template match="emph" /&gt; &lt;!-- &lt;emph&gt; nodes get their special treatment here --&gt; &lt;xsl:template match="emph" mode="text"&gt; &lt;!-- effectively, this copies the text node via the identity template --&gt; &lt;xsl:apply-templates /&gt; &lt;!-- copy the first following node - if it is a text node (this is to get interspersed spaces into the output) --&gt; &lt;xsl:if test=" generate-id(following-sibling::node()[1]) = generate-id(following-sibling::text()[1]) "&gt; &lt;xsl:apply-templates select="following-sibling::text()[1]" /&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It results in:</p> <pre><code>&lt;reference&gt; &lt;strong&gt;Antony, R. and Micheal, V.&lt;/strong&gt; &lt;em&gt;reference title&lt;/em&gt; &lt;/reference&gt; </code></pre> <hr> <p>I'm not overly happy with</p> <pre><code>&lt;xsl:variable name="merge" select=". | following-sibling::emph[ @type = current()/@type and generate-id(preceding-sibling::emph[@type != current()/@type][1]) = $boundary ]" /&gt; </code></pre> <p>if someone has a better idea, please tell me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload