Altova Mailing List Archives

[xsl] Processing tag text either side of nested tags

From: "Neil Crofts" <neil.crofts@--------->
Date: 4/11/2006 2:39:00 PM
I have some XML with text contained either side of a nested tag. I
would like to apply a named template to the text parts such that I
modify the text but also preserve the nested tags as-is. For example,
I have some XML of the form:

<outer> hello there <inner name="alpha">beta gamma</inner> goodbye then

...and I need to transform it to the following format:

<outer> HELLO THERE <inner name="alpha">beta gamma</inner> GOODBYE THEN

where in this case a named template converts the text to upper case,
although ideally the conversion function would be arbitrary.

I have made a number of attempts so far at doing this, but without
success. For example:

    <!-- Identity template -->
    <xsl:template match="@*|node()">
            <xsl:apply-templates select="@*|node()"/>

    <!-- Outer template -->
    <xsl:template match="outer">
            <xsl:copy-of select="@*"/>
            <xsl:call-template name="upper">
                <xsl:with-param name="text">
                    <xsl:apply-templates select="node()"/>

    <!-- Convert text to upper case -->
    <xsl:template name="upper">
        <xsl:param name="text"/>
        <xsl:value-of select="translate($text,
'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>

The above results in:


I understand why this is producing that, but I just can't figure out
how to apply the named template to only the text parts of the <outer>
tag, while copying the nested <inner> tag as-is.

Thanks in advance for any insight into how to resolve this problem.


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.