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

Re: template matching everywhere

Subject: Re: template matching everywhere
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 04 Mar 2004 18:39:02 -0500
xsl apply template everywhere
Hi JF,

At 06:06 PM 3/4/2004, you wrote:
I would like to write a template that match a particular element but this element could be located anywhere

No problem: templates are generally written to match elements no matter where they appear (though you can go to extra trouble to restrict this behavior).


<ROOT>
   <NODE>
      maybe some text here
      <TOBEMATCHED>    </TOBEMATCHED>
      maybe some text here
   </NODE>
   <NODE>
      <SUBNODE>
          maybe some text here
          <TOBEMATCHED>   </TOBEMATCHED>
          maybe some text here
      </SUBNODE>
      <SUBNODE>
          <SUBSUBNODE>
               maybe some text here
              <TOBEMATCHED>   </TOBEMATCHED>
              maybe some text here
          </SUBSUBNODE>
      </SUBNODE>
   </NODE>
</ROOT>

I would like to write a template that allow me to automatically translate the TOBEMATCHED element while processing his parent.

The way the XSLT processing model works, you don't translate TOBEMATCHED while processing its parent; you output the result you want from TOBEMATCHED when you process TOBEMATCHED itself:


<xsl:template match="TOBEMATCHED">
  <!-- this works wherever TOBEMATCHED occurs, assuming the node
       is selected for processing at all -->
  <output>
    <xsl:apply-templates/>
  </output>
</xsl:template>

...which will replace every TOBEMATCHED element with an <output> element.

For example suppose you have to proceed an HTML document and you want to replace each <b> tag with an <em> tag and did other work on other it may help you understand what I want to do.

<xsl:template match="b"> <em> <xsl:apply-templates/> </em> </xsl:template>

Assuming you do not override the default node traversal of the document, this will result in all <b> elements occuring anywhere with <em> elements (and will go on to process the rest of the document too).

This is so basic to XSLT that I wonder where the gap is. Have you looked at any introductory material on the XSLT processing model? It might also be instructive to you to try a simple stylesheet containing nothing but a template or two like this one.

My guess is that if you can't get this to work, it's because you are making things too complicated. Maybe posting a complete sample with a stylesheet that you believe should work, but doesn't, can help us understand where to direct your attention.

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.