Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my method, which uses recursive calls of a template to match elements with the same type.</p> <p>It first matchs the first 'emph' element, and them recursively calls a template matching 'emph' elements of the same type. Next, it repeats the process matching the next 'emph' element of a type different to the one currently matched.</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="html" encoding="utf-8"/&gt; &lt;!-- Match root element --&gt; &lt;xsl:template match="reference"&gt; &lt;p class="reference"&gt; &lt;!-- Match first emph element --&gt; &lt;xsl:apply-templates select="emph[1]"/&gt; &lt;/p&gt; &lt;/xsl:template&gt; &lt;!-- Used to match first occurence of an emph element for any type --&gt; &lt;xsl:template match="emph"&gt; &lt;xsl:variable name="elementname"&gt; &lt;xsl:if test="@type='bold'"&gt;strong&lt;/xsl:if&gt; &lt;xsl:if test="@type='italic'"&gt;em&lt;/xsl:if&gt; &lt;/xsl:variable&gt; &lt;xsl:element name="{$elementname}"&gt; &lt;xsl:apply-templates select="." mode="match"&gt; &lt;xsl:with-param name="type" select="@type"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:element&gt; &lt;!-- Find next emph element with a different type --&gt; &lt;xsl:apply-templates select="following-sibling::emph[@type!=current()/@type][1]"/&gt; &lt;/xsl:template&gt; &lt;!-- Used to match emph elements of a specific type --&gt; &lt;xsl:template match="*" mode="match"&gt; &lt;xsl:param name="type"/&gt; &lt;xsl:if test="@type = $type"&gt; &lt;xsl:value-of select="."/&gt; &lt;xsl:apply-templates select="following-sibling::*[1]" mode="match"&gt; &lt;xsl:with-param name="type" select="$type"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Where this currently fails though, is that it doesn't match the whitespace in between the 'emph' elements.</p>
    singulars
    1. This table or related slice is empty.
    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. 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