xsl-list
[Top] [All Lists]

Re: [xsl] Processing tag text either side of nested tags

2006-04-11 08:16:15
Thanks to everyone who has responded to my query so far (Andrew, Jon,
David and Wendel).

I understand the issue now. This has been an area which has been
causing me confusion for some time and I think collectively you've all
just helped me to the next level of understanding of XSLT. Great work.

Thanks also for the warning about the T word :-)

Regards,
Neil



On 11/04/06, Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com> wrote:
Neil,

I think the solution to your problem is to match text nodes, but only
the text nodes you want. (Let the built-in template match the others.)

As in,

<xsl:template match="outer/text()">
   ... upshift here ...
</xsl:template>

Since this won't match the text nodes inside the inner, they will be 
untouched.

I hope that helps,
Wendell

At 10:38 AM 4/11/2006, you wrote:
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 </outer>

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

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

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:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

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

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


The above results in:

<outer>HELLO THEREBETA GAMMAGOODBYE THEN</outer>

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.


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>