[xsl] Wrapping around textual and element node at the same time

Subject: [xsl] Wrapping around textual and element node at the same time
From: Gábor Tóth <roysy@xxxxxxxx>
Date: Thu, 9 Sep 2010 09:29:42 +0100
Dear All,

I am trying to wrap around words in a paragraph which looks like this.


<text><p><gliph>T</gliph>his is a very short
parapraph.<gliph>I</gliph>t is also tricky. </p> </text>


The result what I would like,  should look like this.

<text>
    <p>
        <seg><gliph>T</gliph>his</seg>
        <seg>is</seg>
        <seg>a</seg>
        <seg>very</seg>
        <seg>short</seg>
        <seg>parapraph.</seg>
        <seg><gliph>I</gliph>t </seg>
        <seg>is</seg>
        <seg>also</seg>
        <seg>tricky.</seg>
    </p>
</text>

For wrapping around all words I use this template.

<xsl:template match="text/p/text()">


        <xsl:analyze-string select="." regex="\w+">

            <xsl:matching-substring>


                <seg ><xsl:value-of select="."/></seg>

            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="."/>
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>

However, this template wraps around only the textual nodes but cannot do this:

<seg><gliph>T</gliph>his</seg>.

Is there any way to wrap around a textual node and an element node together?

Or should I do the wrapping first and then moving the gliph element later?

Thanks,

Gabor

Current Thread