+ <variable name="params-string">
+ <choose>
+ <when test="starts-with($shebang, '#!lesml@')">
+ <value-of select="substring-after($shebang, '$')"/>
+ </when>
+ <otherwise>
+ <value-of select="substring-after($shebang, '#!lesml')"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="params-fragment">
+ <choose>
+ <when test="$shebang!=''">
+ <html:dl>
+ <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
+ <html:div>
+ <html:dt>
+ <text> LANG </text>
+ </html:dt>
+ <html:dd>
+ <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
+ </html:dd>
+ </html:div>
+ </if>
+ <for-each select="exslstr:tokenize($params-string)">
+ <choose>
+ <when test="contains(., '=')">
+ <html:div>
+ <html:dt>
+ <value-of select="substring-before(., '=')"/>
+ </html:dt>
+ <html:dd>
+ <value-of select="substring-after(., '=')"/>
+ </html:dd>
+ </html:div>
+ </when>
+ <otherwise>
+ <html:div>
+ <html:dt>
+ <value-of select="."/>
+ </html:dt>
+ <html:dd/>
+ </html:div>
+ </otherwise>
+ </choose>
+ </for-each>
+ </html:dl>
+ </when>
+ <when test="$parent-params">
+ <copy-of select="$parent-params"/>
+ </when>
+ <otherwise>
+ <html:dl/>
+ </otherwise>
+ </choose>
+ </variable>
+ <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()])"/>