[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: "Glenn MacGregor" <gtm@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 19 Feb 2004 17:41:09 -0500
cdata select

Thanks for the response! The following messages may shead some light on why
I am doing it this way.

Although my input no longer looks like:

<tr><td><var/> Test</td><td><var/> Test</td></tr>

It looks like:

<foreach param="devices">
<tr><td><b>BOLDFACE</b> Some Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>

Along with this fragment of XML I also have another XML file name @param.xml
(devices.xml) which contains an XML list of all the devices I want to loop

so here is the foreach template:
  <xsl:template match="foreach">
  <xsl:variable name="foreachNode" select="current()" />
  <xsl:variable name="nodeLocation" select="concat($tmpdir,@param,'.xml')"
     <xsl:for-each select="document($nodeLocation)/doc/item">
        <xsl:call-template name="foreachOutput">
         <xsl:with-param name="cdata" select="text()" />
         <xsl:with-param name="do-sect" select="$foreachNode/*" />

Opens the devices.xml file and gets each item calling foerachOutput with
$cdata = dev1 ... and do-sect = all the children of the current node.

Here is the foreachOutput template:
  <xsl:template name="foreachOutput">
    <xsl:param name="cdata" />
    <xsl:param name="do-sect" />
    <xsl:for-each select="$do-sect">
            <xsl:when test="name() = 'replace'">
                <xsl:call-template name="replaceImage">
                    <xsl:with-param name="var" select="$cdata" />
            <xsl:when test="name() = 'variable'">
                <xsl:call-template name="insertVariable">
                    <xsl:with-param name="var" select="$cdata" />
                <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" />

  We have no "replace" or "variable" tags (which I do need to handle
differently than all the other tags), we are in the xsl:otherwise but I get
no text output only the tags and attributes of those tags. I need to output
all the text inside the tags (expect for the "variable" and "replace" tags.
Any clues?

  Thanks for any help!


----- Original Message -----
From: "Wendell Piez" <wapiez@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, February 19, 2004 4:43 PM
Subject: Re:  Selecting and printing certain nodes

> 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.
> >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
> >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,
> test="name()='variable'" will never be true.
> Beyond this, however, is a mystery. For one thing, as given your code
> 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
> a reason why you aren't using the standard template-driven approach? If
> 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
> 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
> 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

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.