[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Selecting and printing certain nodes

Subject: Re: Selecting and printing certain nodes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Feb 2004 16:43:40 -0500
xslt print element name
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:
<xsl:template name="foreachOutput">
    <xsl:param name="cdata"/>
    <xsl:param name="do-sect"/>
    <xsl:for-each select="$do-sect">
        <xsl:choose>
            <xsl:when test="name() = 'variable'">
                <xsl:call-template name="insertVariable">
                    <xls:with-param name="var" select="$data"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <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"/>
                    </xsl:call-template>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>
    <xsl:for-each>
</xsl:template>

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

(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. :->

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx 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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.