Re: [xsl] best practices, insert PI with XSLT or otherwise?
Subject: Re: [xsl] best practices, insert PI with XSLT or otherwise?|
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 03 Feb 2010 06:35:17 +0100
At 2010-02-02 23:14 -0500, Hoskins & Gretton wrote:
HI, I have a set of XML files in which I want to insert a processing
instruction after the XML declaration. I could use a text function
type of "search and replace" or XSLT identity template + override. I
work with a Java programmer, so everything can be solved best with
Java from her point of view, and I work with XSLT, so you know my
preference. Is there ever a reason that a non-XSLT process would be
better than XSLT?
When that Java programmer doesn't know how to work with Unicode. A
couple of times now I've supplied a pure XML/XSLT solution to a
customer only to have them make an 11th hour change using Java in the
last mile of delivery and having the Java programmer muck up the
encoding in the file.
Reading the XML Declaration (or lack thereof) informs the Java
programmer about the character set for the rest of the document, but
they may not know that and just blindly run the file through their
"quick and dirty and why should I bother debugging such a simple
change" program like a bull in a china shop breaking things along the way.
Injecting a PI after an XML declaration doesn't need to take
advantage of the node structure of XML in order to reliably locate
the position in the stream where the injection takes place. So it
would be the Unicode aspects of an XML processor I would rely on to
make such a change reliable.
But character set issues aside, I would be hard-pressed to defend
building the entire node tree for your XML document just to inject
something that doesn't need the entire node tree to be located.
You might draw the "everything else with this file is done with
XML-aware processing, so why not this" card to promote
consistency. But that would be trumped by performance questions on
very large files that really don't need to be converted to a node
tree to accomplish what you need.
I hope this helps.
. . . . . . . . . . . Ken
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30
Vote for your XML training: http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal