+ <variable name="params" select="exsl:node-set($params-fragment)/*"/>
+ <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
+ <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
+ <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
+ <if test="starts-with($first-line, '##') and $first-line!='##'">
+ <call-template name="LesML:comment-out">
+ <with-param name="source" select="substring-after($first-line, '##')"/>
+ </call-template>
+ </if>
+ <if test="$doclines[normalize-space()!='']">
+ <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
+ <element name="article" namespace="&xhtml;">
+ <for-each select="$params/html:div/html:dt[string()=' LANG ']">
+ <attribute name="lang">
+ <value-of select="following-sibling::html:dd"/>
+ </attribute>
+ <attribute name="xml:lang">
+ <value-of select="following-sibling::html:dd"/>
+ </attribute>
+ </for-each>
+ <for-each select="$params/html:div/html:dt[string()='profile']">
+ <attribute name="data-lesml-profile">
+ <value-of select="following-sibling::html:dd"/>
+ </attribute>
+ </for-each>
+ <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
+ <element name="footer" namespace="&xhtml;">
+ <attribute name="class">
+ <text>head</text>
+ </attribute>
+ <for-each select="$record-separators">
+ <variable name="position" select="position()"/>
+ <variable name="prev-separator" select="$record-separators[($position)-1]"/>
+ <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
+ <if test="$fields">
+ <element name="dl" namespace="&xhtml;">
+ <for-each select="$fields">
+ <choose>
+ <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
+ <otherwise>
+ <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
+ <element name="div" namespace="&xhtml;">
+ <element name="dt" namespace="&xhtml;">
+ <value-of select="normalize-space(substring-before(., ':'))"/>
+ </element>
+ <element name="dd" namespace="&xhtml;">
+ <variable name="firstline">
+ <choose>
+ <when test="contains(., ':')">
+ <value-of select="normalize-space(substring-after(., ':'))"/>
+ </when>
+ <otherwise>
+ <value-of select="normalize-space(.)"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <choose>
+ <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+ <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
+ </when>
+ <otherwise>
+ <value-of select="$firstline"/>
+ </otherwise>
+ </choose>
+ <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
+ <variable name="nextline" select="normalize-space(.)"/>
+ <choose>
+ <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+ <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
+ </when>
+ <otherwise>
+ <value-of select="$nextline"/>
+ </otherwise>
+ </choose>
+ </for-each>
+ </element>
+ </element>
+ </otherwise>
+ </choose>
+ </for-each>
+ </element>
+ </if>
+ <if test=".!='%%'">
+ <call-template name="LesML:comment-out">
+ <with-param name="source" select="substring-after(., '%%')"/>
+ </call-template>
+ </if>
+ </for-each>
+ </element>
+ </if>
+ <element name="div" namespace="&xhtml;">
+ <attribute name="class">
+ <text>body</text>
+ </attribute>
+ <call-template name="LesML:paragraphize">
+ <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
+ </call-template>
+ </element>
+ </element>
+ </if>
+ <if test="$docsep">
+ <call-template name="LesML:parse">
+ <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
+ <with-param name="parent-params" select="$params"/>
+ </call-template>
+ </if>
+ </template>
+ <template name="LesML:block">
+ <param name="lines" select="/.."/>
+ <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
+ <for-each select="$last-lines">
+ <variable name="position" select="position()"/>
+ <variable name="prev-last" select="$last-lines[($position)-1]"/>
+ <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
+ <variable name="prefix" select="substring(translate(., ' 	', ''), 1, 1)"/>
+ <variable name="all-prefixed" select="not($linespans[not(starts-with(translate(., ' 	', ''), $prefix))])"/>
+ <variable name="quoted" select="$all-prefixed and $prefix='»'"/>
+ <variable name="bracketed" select="$all-prefixed and $prefix=']'"/>
+ <choose>
+ <when test="count($linespans)=1 and translate(., concat($LESML_SECTION_BREAK_CHARS, ' 	'), '')=''">
+ <element name="hr" namespace="&xhtml;"/>
+ </when>
+ <when test="$quoted or $bracketed">
+ <variable name="innerlines-fragment">
+ <for-each select="$linespans">
+ <variable name="inner">
+ <value-of select="substring-after(., $prefix)"/>
+ </variable>
+ <copy>