Re: [xsl] Confusing namespaces and xslt
Subject: Re: [xsl] Confusing namespaces and xslt|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 29 Sep 2008 16:39:06 -0400
At 03:44 PM 9/29/2008, you wrote:
What would be the best way to actually take the input xml transform it
into a new xml and just change a value or add a new element?
The best approach is to adapt the "identity transform", amending it
with a bit of extra logic to effect the changes you want.
This is a well-documented approach, once you know the keywords. As
you might imagine, an identity transform is one in which the output
replicates the input. Strictly speaking, what you are trying to write
might be called a "near-identity transform" -- this might be as
simple as adding a template.
Would it be best to do a template match on "/" and do a for-each on
each element and then test each element to see if it was the one I
wanted to change?
No. It would be best to use template matching, as the standard
identity transform does. Its operation is fairly simple and
straightforward, albeit obscure if you don't know how XSLT templates
work. But by the same token, it's an excellent lesson in templates,
which is indispensable for anyone working with XSLT, and something
you're much better off getting sooner rather than later.
Use your favorite search engine to find writeups and you should be
set. Ask back here if what you find isn't enough.
Would it be better to set up specify template match statements for
each of the top-level elements and output the xml from the input
document except in the case where I need to change it?
Kind of ... the identity template (the heart of the logic) simply
copies input to output. Then, yes, you add templates to catch the
cases where you want to do something differently, like add or change
or remove something. I say "kind of" since the template matches all
nodes, not just nodes at the top level.
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