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

Re: Convert XML to Excel using XSLT Question II.

Subject: Re: Convert XML to Excel using XSLT Question II.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2006 12:09:41 -0400
xslt convert to excel
Karen,

At 03:42 PM 6/20/2006, you wrote:
As you said, if the XSLT will go through each node and find the match,
and apply-template when no "select =" would apply to the current
node's children, then in my following example, if I comment out the
<xsl:apply-template/>, I would assume other nodes other than the root
would still get worked on the rules, because I have other code
paragraphs/templates to match the other nodes. Then it doesn't seem to
be necessary to put a <xsl:apply-template> here. But when I commented
it out, all the rest nodes are ignored. Only <workbook ....>
<worksheet></worksheet></workbook>. Can you please explain this?

Simply, your assumption is incorrect.


Consider this template:

<xsl:template match="foo">
  <br/>
</xsl:template>

If this template allows the child nodes of the foo element to be processed, should the results of their processing be placed before the br element, or after?

In other words, a model such as you described would be underspecified with respect to a very important aspect of the building of the result tree -- the order of the elements that appear in it.

If, in contrast, we have

<xsl:template match="foo">
  <br/>
  <xsl:apply-templates/>
</xsl:template>

we know exactly where the br should appear relative to the results of applying templates to the children of the matched node.

Having the instruction be explicit also allows us to:

1. Do it more than once
2. Apply templates to any nodes we like (not just the children)

The presence of other templates to match other nodes has no effect on whether those nodes are processed or not. It's perfectly fine, even normal, to have templates to match nodes that do not even appear in the source document (because they might appear in some other source document).

In order to understand the XSLT processing model properly, you need to understand that:

1. Applying templates does *not* happen just because a template is present
2. Nevertheless, since the built-in default templates (for elements and the root) contain apply-templates instructions, the tree will be traversed completely by default in any case.
3. Yet, this default behavior is easy to override, at any level of the tree, simply by writing a template that does not contain an apply-templates instruction. This is an important, and very useful, feature of the language.


I hope this helps.

Cheers,
Wendell

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.