Re: [xsl] Selecting and printing certain nodes

Subject: Re: [xsl] Selecting and printing certain nodes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Feb 2004 16:43:40 -0500
Hi Glenn,

At 04:02 PM 2/19/2004, you wrote:
I am having a problem printing certain nodes to the result tree. Here is
the XML I am working on:

<tr><td><b>Before</b> After Variable</td/</tr>

I have it to the point where I am printing the <tr>,<td> and <b> tags. The
problem is the result is:
<tr><td><b></b></td></tr>  Where did all my text go?

<xsl:template name="foreachOutput">
    <xsl:param name="cdata"/>
    <xsl:param name="do-sect"/>
    <xsl:for-each select="$do-sect">
            <xsl:when test="name() = 'variable'">
                <xsl:call-template name="insertVariable">
                    <xls:with-param name="var" select="$data"/>
                <xsl:element name="{name()}">
                    <xsl-copy-of select="@*"/>
                    <xsl:call-template name="foreachOutput">
                        <xsl:with-param name="do-sect" select="./*"/>
                        <xsl:with-param name="cdata" select="$cdata"/>

>From the above snipit of XML (<tr><td>...) I assume I am not getting into
the <xsl:when test="name()='variable'"> section so I am in the
<xsl:otherwise> which uses the <xsl:element>

That's a fair assumption. Since you don't have any <variable> elements, the test="name()='variable'" will never be true.

Beyond this, however, is a mystery. For one thing, as given your code won't work -- there's no assignment of a value to a variable $data; and it looks as though nothing will ever be assigned to $cdata either.

Which really raises the question of why you are writing a recursive template to do what the XSL processor will do for you in any case. Is there a reason why you aren't using the standard template-driven approach? If you want your output to look just like your input, the identity template provides for this:

<xsl:template match="node()">
    <xsl:copy-of select="@*"/>

(In this case, the text will be copied to output by virtue of matching the built-in template for text nodes, which copies the value of the node to the result.)

But even if you don't want your output exactly like your input, plain-vanilla XSLT template matching is far easier and more flexible, too.

Please elucidate: we need more context for your code, both how it's getting invoked, and why you're doing it this way and not the easy way. :->


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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:

Current Thread