xsl-list
[Top] [All Lists]

Re: [xsl] XSLT Hello World

2014-03-25 09:36:07
...
Indeed, the Hello World I like to use looks like this:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

</xsl:stylesheet>

I.e., a stylesheet with no templates at all. (You can also write it
as an empty element if you prefer.)

Not XSLT 2.0, but without a template as you requested (from [1]):

<?xml-stylesheet href="#" type="text/xsl"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <b><xsl:value-of select="concat('hello, ', 'world')"/></b>
</html>

This would be minimal, just click [2]:
<?xml-stylesheet href="#" type="text/xsl"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
Hello world</html>


[1]
https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/literal_result_element_as_stylesheet_in_big5_browsers16
[2] http://stamm-wilbrandt.de/en/xsl-list/hello0.xsl.xml


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Level 3 support for XML Compiler team and Fixpack team lead
WebSphere DataPower SOA Appliances
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/
http://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


                                                                                
                                                           
  From:       Wendell Piez <wapiez(_at_)wendellpiez(_dot_)com>                  
                                                                      
                                                                                
                                                           
  To:         xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com,                 
                                                                            
                                                                                
                                                           
  Date:       03/24/2014 05:05 PM                                               
                                                           
                                                                                
                                                           
  Subject:    [xsl] XSLT Hello World                                            
                                                           
                                                                                
                                                           





Hi,

Over in that other thread, Ihe said:

Extracting text from an XML document is the hello world of XSLT.
text() would appear to be an obvious way of doing that and it's really
important that it entails no surprises. If I were an XSLT antagonist
that is exactly the sort of thing I would  home in on to portray the
language as arcane, difficult to use and not suitable for my project.

I find this really quite interesting.

One thing I stress to beginners is that if they're starting to learn
the language using only a syntax reference plus whatever they might
know about Perl, Python or Java, they are heading for a world of hurt.

It's not like your granddaddy's programming language, and when you
assume things like "text() is the way to get my data into the output,
because it says 'text'" ... ouch.

Indeed, the Hello World I like to use looks like this:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

</xsl:stylesheet>

I.e., a stylesheet with no templates at all. (You can also write it as
an empty element if you prefer.)

After having acknowledged our astonishment at the results of running
this, we can talk about the built-in templates. And then we start
writing templates of our own ... matching elements, not text nodes. We
do this with a source document with mixed content (such as <doc>Hello
<who>World</who></doc> ), (so we can try a few things out such as
matching elements in line), and then a slightly more elaborate
instance (perhaps including some comments or processing instructions
so we can illustrate aspects of the data model, such as text nodes) .

Take in a few points of fact, practice for an hour or two, and get a
good night's sleep, and you no longer run the risk that you will be
surprised by 'text()' in XSLT.

Talking about the processing model in the context of documents with
mixed content also gives us an early opportunity to start thinking
about XSLT's purposes, strengths and weaknesses.

I know this approach may reinforce the impressions of some programmers
that XSLT is, as Ihe says, "arcane, difficult to use and not suitable
for my project". To this my only answer is in the doing of it.
Assuming your problem is in fact in XSLT's sweet spot, showing how
powerful and easy XSLT is ... once you have a clue ... answers the
critique by itself.

If your problem isn't in XSLT's sweet spot, I ask why are you
interested in it. Yes, XSLT is generally very powerful, and can be
used for problems often quite different from the kinds of document
processing for which it was designed. But please please don't expect
an easy time trying to tackle one of those in XSLT before you have a
feel for templates and traversals.

The thing about "arcane" is also relative. Indeed, if you aren't
naturally a curious sort with a reasonable tolerance for the arcane,
one wonders why you expect to do well with programming at all.

Cheers, Wendell


--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>