1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.org/mf"
exclude-result-prefixes="xs mf">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="* | @* | text()">
<xsl:copy>
<xsl:apply-templates select="* | text() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:param name="max-level" as="xs:integer" select="3"/>
<xsl:function name="mf:group" as="node()*">
<xsl:param name="items" as="node()*"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:variable name="name" select="('rom', 'num', 'par')[$level]"/>
<xsl:for-each-group select="$items" group-starting-with="par[@type = $name]">
<xsl:choose>
<xsl:when test="self::par[@type = $name]">
<xsl:element name="SENSE">
<xsl:copy-of select="."/>
<xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
</xsl:element>
</xsl:when>
<xsl:when test="$level lt $max-level">
<xsl:sequence select="mf:group(current-group(), $level + 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:function>
<xsl:template match="ex">
<xsl:copy>
<xsl:sequence select="mf:group(*, 1)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[preceding-sibling::*[self::par[@type='rom'] or self::par[@type='num']][1]/self::par[@type='rom'] ]">
<xsl:choose>
<xsl:when test=".[following-sibling::*[self::par[@type='rom'] or self::par[@type='num']][1]/self::par[@type='num']][not(self::par[@type='rom'])] [not( self::par[@type='num'])]">
<span>
<xsl:copy-of select="."/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> |
Partager