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

RE: xsl:apply-templates behaving differently depending

Subject: RE: xsl:apply-templates behaving differently depending on the node copied?
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Wed, 11 May 2005 12:02:46 +0000
RE:  xsl:apply-templates behaving differently depending
On your XML (corrected for markup), the following XSL shoukld illustrate the idea:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       version="1.0">
   <xsl:output method="html" />

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

   <xsl:template match="td[count(text()) = 0]">
       <td>
           <xsl:text>__NOTHING__</xsl:text>
           <xsl:apply-templates/>
       </td>
   </xsl:template>

</xsl:stylesheet>

It uses an identity transform to copy everything verbatim, except for empty <td> elements, which are filled-in with default text. You should be able to use some variation of this for what you ultimately need.

Of course, we were lucky here in that we could specifically match empty td elements. Things would not have been quite so easy otherwise. For example, XSL doesn't have a provision for invoking a template on a non-match--there was a thread about just that about 2 months ago.

Regards,

--A

From: knocte <knocte@xxxxxxxxx>

<page>
  <head>
    <title>Example</title>
  </head>

  <content>
    <h1>Example</h1>
    <table>
      <tr>
        <td></td>
        <td>Something #1</td>
      </tr>
      <tr>
        <td>Somthing #2</td>
        <td />
      </tr>
    </table>
  <content>
</page>


And it will convert it to the following:


<html>
  <head>
    <title>Example</title>
  </head>
  <body>
    <div id="content">
      <h1>Example</h1>
      <table>
        <tr>
          <td></td>
          <td>Something #1</td>
        </tr>
        <tr>
          <td>Something #2</td>
          <td />
        </tr>
      </table>
    </div>
  <body>
</html>


But how can I use apply-templates to obtain the following?:


<html>
  <head>
    <title>Example</title>
  </head>
  <body>
    <div id="content">
      <h1>Example</h1>
      <table>
        <tr>
          <td>________NOTHING!_______</td>
          <td>Something #1</td>
        </tr>
        <tr>
          <td>Something #2</td>
          <td>________NOTHING!_______</td>
        </tr>
      </table>
    </div>
  <body>
</html>

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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.