Re: [xsl] Re: Re-arranging an XML file

Subject: Re: [xsl] Re: Re-arranging an XML file
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 22 Jan 2009 11:26:37 -0500
Hi Mike,

At 03:23 AM 1/22/2009, you wrote:
Hi Wendell et. al,

I've inserted the following in my XSL file, but it's being ignored.

<xsl:template match="LastChangedBy">
  <xsl:text>User: </xsl:text>
  <xsl:text>, </xsl:text>

Any ideas as to why?

There are several potential reasons:

1. There are namespace declarations in your input that are qualifying your matches without your knowing it. Solution: read up on namespaces. (If your input has no namespaces defined, this won't be the case. Also, this tends to be all or nothing: if you have this problem, none of your templates will match properly.)

2. There is another template somewhere that is overriding this one, without your knowing it. Solution: understand template matching and the rules for determining template priority when two or more templates match.

3. The nodes that this template is intended to match are never being processed, so there is nothing to match. Solution: examine your template traversal, especially in templates matching ancestors of this node (assuming you are doing an orthodox top-down traversal), and make sure the nodes matching this template are being processed.

There are probably other reasons I can't think of at the moment.

The short version is, we can't know without seeing a sample of your data and a complete stylesheet that reproduces the problem -- preferably a reduced instance of each.

Frequently, developers find that in the process of creating reduced instances to duplicate a particular bug, they discover the reason for the bug. This is a basic and very useful debugging method in XSLT, especially when things get complex.

Absent this additional information, I've tried to offer "capsule diagnoses" to suggest to you where to look -- in keeping with our earlier recommendation that you complement this list by reading up in other resources, especially those that offer a comprehensive description of the XSLT processing model.

Chances are, if you did post minimal examples showing us the entire problem, we'd have to explain the processing model to you in order to explain what's going on. You can leapfrog this entire process by reading up on the processing model yourself. By "processing model" I mean:

What are XSLT's inputs and outputs (tree of nodes, not tags-and-text)
What are templates (I like to call this the Yin of XSLT)
What does apply-templates do (the Yang of XSLT)
What does it mean for a template to match a node (Yin meets Yang)
What happens if no template in your stylesheet matches a node being processed (every Yang has a Yin)

After you initiate yourself into this mystery-that-is-not-a-secret, posts to the list to say "this is so cool" would be very welcome.

Places to start, to complement books and tutorials:

You may find that some of this discussion is over your head at the moment, but that's okay. Like many simple things, XSLT is deep. Things will click if you persist.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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 ======================================================================

Current Thread