[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Application Design
- From: James Strachan <james_strachan@yahoo.co.uk>
- To: Al Snell <alaric@alaric-snell.com>, Mike.Champion@SoftwareAG-USA.com
- Date: Mon, 13 Aug 2001 13:35:00 +0100
I think XSLT is suprisingly complex for non-lisp programmers to pick up and
really understand. I agree with many posters on the list that XSLT is often
used for too much and a programming language should often be used instead.
Its easy for people to forget that most of the power and expressiveness of
XSLT comes from using XPath as an expression language. XPath is fairly easy
to pick up and use in conventional programming languages too.
e.g. here's some Java code using dom4j which uses XPath to process all
hypertext links...
// parse a document
SAXReader reader = new SAXReader();
Document doc = reader.read( "foo.xml" );
// process each hyper text link...
List links = doc.selectNodes( "//a[@href]" );
for (Iterator iter = links.iterator(); iter.hasNext(); ) {
Element a = (Element) iter.next();
String text = a.getText();
String uri = a.attributeValue( "href" );
...
}
Most developers can deal with collections, objects, procedural code and
whatnot quite easily - so I prefer the general approach of using XPath with
a real programming language. Its easier for developers to pick up,
understand and maintain.
> On Sat, 11 Aug 2001 Mike.Champion@SoftwareAG-USA.com wrote:
>
> > Thanks for such a thorough response. I think I need to learn more
> > about PHP; my response took a more generic "procedural vs. declarative"
> > spin. It sounds like PHP (like XSLT) has a bit of both characteristics.
>
> It's almost identical to ASP in many ways. It's different from JSP in that
> JSP has the "custom tags" feature which is nice, but is harder to install
> (classpaths get me every time with Java :-)
I agree custom tags are pretty cool.
There's a JSP custom tag library called XTags which allows people to do
XPath expressions from inside JSP.
http://jakarta.apache.org/taglibs/doc/xtags-doc/intro.html
This allows XPath to be used to process XML (in a similar way to XSLT) while
still being inside a traditional scripting language, JSP, so you can still
use all your existing scripts, code, custom tags and java expressions while
still benefitting from the power and expressiveness of XPath.
For example, here's a piece of JSP for styling the current XML news
headlines from an RSS feed:-
<html>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags"
%>
<head>
<title>XML news</title>
</head>
<body>
<h1>XML news at <%= new Date() %></h1>
<ul>
<xtags:parse
url="http://www.moreover.com/cgi-local/page?o=rss&c=XML%20and%20metadata%20n
ews"/>
<xtags:forEach select="//item">
<li>
<a href="<xtags:valueOf select="link"/>">
<xtags:valueOf select="title"/>
</a>
: <xtags:valueOf select="description"/>
</li>
</xtags:forEach>
</ul>
</body>
</html>
James
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com