XSL przekształca tekst na XML z nieanalizowanym tekstem: potrzeba więcej głębi

Moje dość dobrze sformułowane dane wejściowe (nie chcę kopiować wszystkich danych):

StartThing
Size Big
Colour Blue
coords 42, 42
foo bar
EndThing
StartThing
Size Small
Colour Red
coords 29, 51
machin bidule
EndThing
<!-- repeat a few thousand times-->

Mam poniżej XSL, z którego zmodyfikowałemPrzetwarzaj plik tekstowy za pomocą XSLT

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:param name="text-encoding" as="xs:string" select="'iso-8859-1'"/>
    <xsl:param name="text-uri" as="xs:string" select="'unparsed-text.txt'"/>

    <xsl:template name="text2xml">
        <xsl:variable name="text" select="unparsed-text($text-uri, $text-encoding)"/>
        <xsl:analyze-string select="$text" regex="(Size|Colour|coords) (.+)">    
            <xsl:matching-substring>
                <xsl:element name="{(regex-group(1))}">
                    <xsl:value-of select="(regex-group(2))"/>
                </xsl:element>          
            </xsl:matching-substring>
        </xsl:analyze-string>
    </xsl:template>

    <xsl:template match="/">
        <xsl:call-template name="text2xml"/>    
    </xsl:template>
</xsl:stylesheet>

i działa dobrze podczas analizowania par na elementy i wartości. Daje mi to wyjście:

<?xml version="1.0" encoding="UTF-8"?>
<Size>Big</Size>
<Colour>Blue</Colour>
<coords>42, 42</coords>

Ale chciałbym również zawinąć wartości w znaczniku Thing, aby moje dane wyjściowe wyglądały następująco:

<Thing>
    <Size>Big</Size>
    <Colour>Blue</Colour>
    <coords>42, 42</coords>
</Thing>

Jednym rozwiązaniem może być wyrażenie regularne, które pasuje do każdej grupy linii po każdej „rzeczy”. Następnie dopasowuje podciągi, jak już to robię. Czy może jest jakiś inny sposób na przeanalizowanie drzewa?

questionAnswers(1)

yourAnswerToTheQuestion