+ </if>
+ </variable>
+ <variable name="restoftext">
+ <choose>
+ <when test="starts-with($source, '¶') and contains($source, ' ')">
+ <value-of select="substring-after($source, ' ')"/>
+ </when>
+ <when test="starts-with($source, '¶')"/>
+ <otherwise>
+ <value-of select="$source"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="maybe-langtag">
+ <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
+ <variable name="split-tag-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
+ <with-param name="separator" select="'@'"/>
+ </call-template>
+ </variable>
+ <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
+ </if>
+ </variable>
+ <variable name="langtag">
+ <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
+ <value-of select="$maybe-langtag"/>
+ </if>
+ </variable>
+ <variable name="id">
+ <choose>
+ <when test="string($langtag)!=''">
+ <value-of select="substring($id-and-lang, 1, string-length($id-and-lang)-(string-length($langtag)+2))"/>
+ </when>
+ <otherwise>
+ <value-of select="$id-and-lang"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <if test="string($id)!=''">
+ <attribute name="id">
+ <value-of select="$id"/>
+ </attribute>
+ </if>
+ <if test="string($langtag)!=''">
+ <attribute name="lang">
+ <value-of select="$langtag"/>
+ </attribute>
+ <attribute name="xml:lang">
+ <value-of select="$langtag"/>
+ </attribute>
+ </if>
+ <value-of select="$restoftext"/>