Any XSL experts?
12 Message(s) by 6 Author(s) originally posted in java programmer
| From: Mark Space |
Date: Tuesday, October 23, 2007
|
Here's a problem that's driving me nuts.
The
program below executes correctly as is. There's one
line in the xsl
string commented out. If you uncomment that line, the
output changes.
It adds the line "I can not jump." That's the value of the
<jump> tag .
But I do not ask for this tag to be put in the output anywhere in the xsl
file , so I do not understand why it's appearing in the output.
Can anyone shed some illumination on this conundrum?package xslweirdness;
import JAVA.io.StringReader;
import JAVAx.xml.transform.Transformer;
import JAVAx.xml.transform.TransformerFactory;
import JAVAx.xml.transform.stream.StreamResult;
import JAVAx.xml.transform.stream.StreamSource;
public
class Main {
private final static String xml = "
<?xml version=\"1.0\"?>\n"
+"
<monkey>\n"
+"
<boy can=\"no\">\n"
+"
<jump>I can not jump.
</jump>\n"
+"
</boy>\n"
+"
</monkey>";
private final static String xsl = "
<xsl:stylesheet "
+"xmlns:xsl=\"http://www.w3.org/1999/XSL /Transform\" "
+"version=\"1.0\">\n"
+"
<xsl:output method=\"html\"/>"
+"
<xsl:template match=\"/monkey\" >\n"
+" Jumping:
<xsl:value-of select=\"boy/@xxxxxxxxxxx\" />\n"
// +"
<xsl:apply-templates/>"
+"
</xsl:template>\n"
+"
</xsl:stylesheet>";
public static void main(String[] args) throws Exception {
System.out.println( "
XML :--------------------\n" + xml );
System.out.println( "XSL:--------------------\n" + xsl );
StreamSource xslSrc = new StreamSource( new StringReader(xsl) );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer xfrm = tf.newTransformer(xslSrc);
StreamResult stmOut = new StreamResult( System.out );
StreamSource xmlSrc = new StreamSource( new StringReader(xml) );
System.out.println( "transform:--------------------\n" );
xfrm.transform(xmlSrc, stmOut);
}
}
| From: =?ISO-8859-1?Q?Arne_Vajh=F8j?= |
Date: Tuesday, October 23, 2007
|
wrote in
message :
Here's a problem that's driving me nuts.
The program below executes correctly as is. There's one line in the xsl
string commented out. If you uncomment that line, the output changes.
It adds the line "I can not jump." That's the value of the <jump> tag.
But I do not ask for this tag to be put in the output anywhere in the xsl
file, so I do not understand why it's appearing in the output.
Can anyone shed some illumination on this conundrum?
private final static String xml = "<?xml version=\"1.0\"?>\n"
+" <monkey>\n"
+" <boy can=\"no\">\n"
+" <jump>I can not jump.</jump>\n"
+" </boy>\n"
+" </monkey>";
private final static String xsl = "<xsl:stylesheet "
+"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" "
+"version=\"1.0\">\n"
+" <xsl:output method=\"html\"/>"
+" <xsl:template match=\"/monkey\" >\n"
+" Jumping: <xsl:value-of select=\"boy/@xxxxxxxxxxx\" />\n"
// +" <xsl:apply-templates/>"
+" </xsl:template>\n"
+"</xsl:stylesheet>";
That line tells the XSLT
process or to process stuff inside what
you've found.
There are the
element text inside.
And apperently there are a default template that displays.
I guess you do not want that line !
Arne
| From: Andrew Thompson |
Date: Tuesday, October 23, 2007
|
| From: Mike Schilling |
Date: Wednesday, October 24, 2007
|
wrote in message:
Here's a problem that's driving me nuts.
The program below executes correctly as is. There's one line in the
xsl string commented out. If you uncomment that line, the output
changes. It adds the line "I can not jump." That's the value of the
<jump> tag. But I do not ask for this tag to be put in the output
anywhere in the xsl file, so I do not understand why it's appearing in
the output.
<apply-templates> means to process all child nodes. The default action for
a text node, which you have not overridden, is to output the text.
| From: Mark Space |
Date: Wednesday, October 24, 2007
|
wrote in message:
There are the element text inside.
And apperently there are a default template that displays.
Yeah that's a good way of thinking about it. There's a default element
that says to just print all values. Weird, I think, but I guess that's
how it works. Thanks!
| From: Mark Space |
Date: Wednesday, October 24, 2007
|
wrote in message:
<http://www.w3schools.com/xsl/xsl_apply_templates.asp>
"The <xsl:apply-templates> element applies a template
to the current element *or to the current element's child
nodes.*"
My use of *bold*.
If that line is changed to ..
+" <xsl:apply-templates select='boy'/>"
.the "I can not jump." line is printed, if changed to..
+" <xsl:apply-templates select='monkey'/>"
.it isn't.
* My WAG is - that line prints because you 'told it to'.
As Arne said, there appears to be a default element. In a "real" xsl
file there are a lot more xsl:templates. I assumed those'd be
matched. The presence of a "default" template really kinda fouls things
up, imo. I appreciate that you
point ed out that the select
command
could be used to modify this behavior, that's probably just what I need.
I'm still trying to wrap my head around how the parse "sees" the
transform.
Thanks for the info!
| From: Mark Space |
Date: Wednesday, October 24, 2007
|
wrote in message:
<apply-templates> means to process all child nodes. The default action for
a text node, which you have not overridden, is to output the text.
That makes more sense: because no action was specified, a default one
was supplied. Thanks!I'm still trying to wrap my head around how the processing actually
occurs. Since this is just basically a fun project, it does not matter
if I can ultimately get everything working just perfect. That's good,
because the more I look at the actual input file, the more it appears it
wasn't designed with any kind of XSL in mind.
| From: Pavel Lepin |
Date: Wednesday, October 24, 2007
|
Follow-ups set to comp.text.xml.
wrote in message in
<ZQDTi.235$Nz7.5@xxxxxxxxxxx>:
wrote in message:
<apply-templates> means to process all child nodes. The
default action for a text node, which you have not
overridden, is to output the text.
The meaning of xsl:apply-templates without select
attribute
is described in detail in XSLT 1.0 spec, 5.4. Built-in
template rules are described in 5.8.
I'm still trying to wrap my head around how the processing
actually occurs.
Unless I have mistaken the intent of your question, here's the
gist of how XSLT processing works:
An XSLT stylesheet is a set of templates describing how to
construct result
tree fragment s, using
literal result
elements, xsl:element, xsl:attribute, xsl:value-of etc.
Those templates are applied to various node
list s.
Of particular interest is xsl:apply-templates and similar
constructs (xsl:apply-imports, xsl:for-each). Those
construct a resulting tree fragment by selecting a nodeset
(by evaluating an XPath
expression in select attribute if
specified, or as described in 5.4 otherwise), using it as
current node list and applying templates to it.
The template chosen for every node or attribute in a node
list depends on a set of
hairy rules described in 5.5,
involving stuff like 'import precedence', template
specificity, priority attributes on corresponding
xsl:template elements, mode attribute of
xsl:apply-templates, and the particular instruction invoked
to apply templates, but most of that is of little interest
unless/until you
run into problems with it.
To start the transformation, an XSLT processor selects the
document node (/) as a current node list and applies
templates to it. The process continues recursively until a
template is reached that constructs a resulting tree
fragment without applying templates to anything else.
How does that work with your
sample document and stylesheet:
1. Current node list: document node (/).
Template applied (built-in):
<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
2. Current node list:
root element 'monkey'.
Template applied:
<xsl:template match="/monkey">
 Jumping:
<xsl:value-of select="boy/@xxxxxxxxxxx"/>
Â
<xsl:apply-templates/>
</xsl:template>
3. Current node list: element 'boy'.
Template applied (built-in):
<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
4. Current node list: element 'jump'.
Template applied (built-in):
<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
5. Current node list: text node 'I can not jump'.
Template applied (built-in):
<xsl:template match="text()|@xxxxxxxxxxx*">
<xsl:value-of select="."/>
</xsl:template>
The
RTF for 5 therefore is:
I can not jump.
For 4 and 3:
I can not jump.
For 2:
Jumping: no
I can not jump.
For 1:
Jumping: no
I can not jump.
That's good, because the more I look at the actual input
file, the more it appears it wasn't designed with any
kind of XSL in mind.
I fail to see what leads you to this conclusion.
Oh, and:
wrote in message in
<7a264236381b4@xxxxxxxxxxx>:
<http://www.w3schools.com/xsl/xsl_apply_templates.asp>
"The <xsl:apply-templates> element applies a template
to the current element *or to the current element's child
nodes.*"
Just goes to show you how little clue those guys at
w3schools have. Not the first time they've been caught at
blatant lies, either.
--
It is rare to find learned men who are clean, don't stink,
and have a sense of humour. -- Liselotte in a letter to
Sophie, 30 Jul 1705
| From: Mark Space |
Date: Wednesday, October 24, 2007
|
wrote in message:
That's good, because the more I look at the actual input
file, the more it appears it wasn't designed with any
kind of XSL in mind.
I fail to see what leads you to this conclusion.
Not the one I posted. The XML file I'm processing. ;-) Thanks for that
explanation, it helped a lot.
Oh, and:
wrote in message in <7a264236381b4@xxxxxxxxxxx>:
<http://www.w3schools.com/xsl/xsl_apply_templates.asp>
"The <xsl:apply-templates> element applies a template
to the current element *or to the current element's child
nodes.*"
Just goes to show you how little clue those guys at
w3schools have. Not the first time they've been caught at
blatant lies, either.
Can anyone recommend a web site or book that'd be a good learning
tool for XSLT? I was looking at the XSLT book by Doug Tidwell published
by O'Reily but I thought I'd ask for other ideas before plunking my
money down.
| From: Joseph Kesselman |
Date: Wednesday, October 24, 2007
|
wrote in message:
Can anyone recommend a web site or book that'd be a good learning
tool for XSLT?
I'm not sure how good it is as a tutorial, but Mike Kay's book on XSLT
was one of the first out and remains a good
reference . At this point I
generally go straight to the spec and/or the XSLT
FAQ website, but I
definitely found Kay's book useful while I was first learning.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
| From: Pavel Lepin |
Date: Thursday, October 25, 2007
|
wrote in message in
<0lLTi.13611$lD6.1357@xxxxxxxxxxx>:
wrote in message:
That's good, because the more I look at the actual input
file, the more it appears it wasn't designed with any
kind of XSL in mind.
I fail to see what leads you to this conclusion.
Not the one I posted. The XML file I'm processing. ;-)
Oh, I see. I have seen a few documents that seemed quite
unsuitable for any imaginable
sort of processing, not just
XSLT.
wrote in message in
<7a264236381b4@xxxxxxxxxxx>:
<http://www.w3schools.com/xsl/xsl_apply_templates.asp>
"The
<xsl:apply-templates> element applies a template
to the current element *or to the current element's
child nodes.*"
Just goes to show you how little clue those guys at
w3schools have. Not the first time they've been caught at
blatant lies, either.
Can anyone recommend a web site or book that'd be a
good learning tool for XSLT? I was looking at the XSLT
book by Doug Tidwell published by O'Reily but I thought
I'd ask for other ideas before plunking my money down.
I've yet to see an XSLT tutorial of quality. XSLT FAQ
<http://www.dpawson.co.uk/xsl/sect2/sect21.html> and
IBM
developerWorks' XML section
<http://www.ibm.com/developerworks/xml> are two
oft-mentioned resources, but both of them aren't exactly
introductory reading. XSLT FAQ is more of an extremely
comprehensive (and somewhat overwhelming) cookbook, while
IBM's resource is a vast collection of articles where it
might be a
bit hard to find something suitable for your
needs. W3C's official XPath and XSLT specifications are
quite maddening and full of devilish legalese, as specs are
wont to be, but might still be of enormous help as
references if you've good enough idea of what you're
looking for. I have been quietly working on a project
codenamed Good Enough XSLT Tutorial for the last few
months, but writing stuff like that just does not seem to be
my forte.
There's one more or less sure-fire way of learning stuff,
and that's solving problems. There are lots of problems in
comp.text.xml archives, and if you crack two or three of
those a day, you're likely to have a very firm grasp of
XSLT basics in a month or so.
--
It is rare to find learned men who are clean, don't stink,
and have a sense of humour. -- Liselotte in a letter to
Sophie, 30 Jul 1705
| From: Mark Space |
Date: Saturday, October 27, 2007
|
wrote in message:
I've yet to see an XSLT tutorial of quality. XSLT FAQ
<http://www.dpawson.co.uk/xsl/sect2/sect21.html> and IBM
developerWorks' XML section
<http://www.ibm.com/developerworks/xml> are two
oft-mentioned resources, but both of them aren't exactly
introductory reading. XSLT FAQ is more of an extremely
There's one more or less sure-fire way of learning stuff,
and that's solving problems. There are lots of problems in
comp.text.xml archives, and if you crack two or three of
those a day, you're likely to have a very firm grasp of
XSLT basics in a month or so.
Thanks for the input. The articles and tutorials at IBM do indeed look
excellent.
I find it hard to read for long periods of time at the computer screen,
so I like to get books. I got Learning XSLT by Michael Fitzgerald, pub.
O'Reilly. After browsing it at the bookstore it looked to be quite
good. Normally I eschew any "learning" or "beginning" books but this
one appeared to have quite a lot of good info. I may even skip Doug
Tidwel's "XSLT" reference book as a result, the spec at w3.org is not
that hard to read.
I also picked up the XSLT Cookbook, also pub. O'Reilly, because of the
many solved problems and examples. After browsing at the bookstore, it
appeared to have many examples of solved problems both esoteric and
practical.
Just in case anyone else was interested in starting books.
Next Message: Why should close() close the underlying stream?
Blogs related to Any XSL experts?
Re: XML/XSLT for web templating
So the alternative is Velocity, Freemarker or JSP and an XML/
Java binding solution (such as JAXP), and this alternative is considered more scalable, more robust and more flexible. In other words, the push is for templates made of:
...
{c2c-jobs-usa} Java .Net SAP FICO BA
using both core and advanced
java technologies (AWT, Servlets , JSP , Swing, Struts, JDBC , RMI , XML ,
XSLT , EJB).Hands-on experience with J2EE Architecture, Application servers and Web servers and a wide
...
EJB & JSP: Java On The Edge, Unlimited Edition by Lou Marco ISBN ...
XML Features XML does not have a fixed set of markup tags, overcoming HTML s greatest deficiency, according to some
experts. XML is not a markup language per se; XML is a meta-markup language that enables document authors to define
...
Calling all Savvy Developers !! Experts, Seniors, Executives ...
A European base Solution Provider in the area of Supply Chain Optimization has multiple Customization Development Consulting position as well as
Java Development positions for it new module due to be launched in 2009.
...
Xml Editor
I decided to start a Developer’s Toolkit area of recommended tools for
any applications developer and I’m starting the list off with Oxygen XML. This is a
Java tool for editing XML,
XSLT and XHTML which runs stand-alone or as an Eclipse
...
Excellent Sr JAVA/J2EE Profile...Available Immediately... IL
Responsible for developing re-usable web services with SOAP protocol and
Java Utility classes to support XML using XML Spy, DOM, SAX, DTD, XML Schemas, XML4J, JAXP 1.1, and
XSL using JAX. · Extensive development using JSP, JNDI, JDBC,
...