Firstly, this structure:
<xsl:variable name="elements">
<xsl:analyze-string select="unparsed-text($file,'utf-8')" regex="[\r\n]">
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
Goves you a variable whose value is a document node containing the concatenated values of the string. You want to keep the strings separate, so use:
<xsl:variable name="elements" as="xs:string*">
<xsl:analyze-string select="unparsed-text($file,'utf-8')" regex="[\r\n]">
<xsl:non-matching-substring>
<xsl:sequence select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
or more simply
<xsl:variable name="elements" select="tokenize(unparsed-text($file,'utf-8'), '[\r\n]')"/>
Secondly in this,
<xsl:apply-templates select="root($node)/ident/."/>
you're think that if "." is then string "fred", then the expression is equivalent to
<xsl:apply-templates select="root($node)/ident/fred"/>
which isn't the case for two reasons: firstly, the value of "." changes on the rhs of "/", and secondly, you can't just substitute a value into an expression and have it treated as part of the expression before evaluating the expression - XSLT is an expression language, not a macro language. You want
<xsl:apply-templates select="root($node)/ident/*[name()=current()]"/>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference