- <variable name="record-separators" select="$noshebang[starts-with(., '%%')]"/>
- <html:article>
- <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="count($record-separators)>1">
- <html:footer class="head">
- <for-each select="$record-separators">
- <variable name="position" select="position()"/>
- <variable name="prev-separator" select="$record-separators[($position)-1]"/>
- <variable name="fields" select="$noshebang[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-separator) or preceding-sibling::*[generate-id()=generate-id($prev-separator)])]"/>
- <if test="$fields">
- <html:dl>
- <for-each select="$fields">
- <choose>
- <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
- <otherwise>
- <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
- <html:div>
- <html:dt>
- <value-of select="normalize-space(substring-before(., ':'))"/>
- </html:dt>
- <html:dd>
- <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="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
- <variable name="nextline" select="normalize-space(.)"/>
+ <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="$noshebang[not($docsep) or following-sibling::*[generate-id()=generate-id($docsep)]]"/>
+ <if test="$shebang!='' or $doclines[normalize-space()!='']">
+ <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
+ <html:article>
+ <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()!='']]">
+ <html:footer class="head">
+ <for-each select="$record-separators">
+ <variable name="position" select="position()"/>
+ <variable name="prev-separator" select="$record-separators[($position)-1]"/>
+ <variable name="fields" select="$noshebang[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-separator) or preceding-sibling::*[generate-id()=generate-id($prev-separator)])]"/>
+ <if test="$fields">
+ <html:dl>
+ <for-each select="$fields">
+ <choose>
+ <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
+ <otherwise>
+ <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
+ <html:div>
+ <html:dt>
+ <value-of select="normalize-space(substring-before(., ':'))"/>
+ </html:dt>
+ <html:dd>
+ <variable name="firstline">
+ <choose>
+ <when test="contains(., ':')">
+ <value-of select="normalize-space(substring-after(., ':'))"/>
+ </when>
+ <otherwise>
+ <value-of select="normalize-space(.)"/>
+ </otherwise>
+ </choose>
+ </variable>