This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes xsl issue for newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xsl issue for newbie" Watch "xsl issue for newbie" New topic
Author

xsl issue for newbie

Rob Patterson
Greenhorn

Joined: May 04, 2004
Posts: 2
Hi there,
I'm trying to render certain data into the browser. In particular:
1. To render all products in stock (which include those already available and will be available 2 days after placing the order) - displaying full product dtls (all elements)
2. To render all products having a delivery charge of less than 3 dollars.
Here's my xml:

Here's my attempt at no.1:

I know the syntax is wrong for the if statement - how should it be done?
And no.2 attempt:

At the moment for the above xsl file, I dont get any results displayed. Where am I going wrong?
At the moment I have to change the file name in the xml doc to select the relevant xsl document - but is there a smart way to be able to create a singe xml document that links to multiple xsl files?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Some quick tips:
1) You need to encode the "<" and ">" within your if statements as "&lt;" and "&gt;"
2) You're referring to "InStock" and "LeadTime" when you should be referring to "Stock/InStock" and "Stock/LeadTime"
3) You've got a typo in "Product/Product"


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
4) If the LeadTime elements have values like "3 working days", you can't do a numeric comparison with "<" etc. Instead, you need to use a string function like substring-before(Stock/LeadTime, ' '), which strips away everything except the number you want to compare with something.
There's a decent XPath/XSL function reference at w3schools.com
Rob Patterson
Greenhorn

Joined: May 04, 2004
Posts: 2
Thanks Lasse,
I used a 'when' instead of the 'if; fixed the typos and it seems to work now. Just got to find a decent parser to use now.
Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsl issue for newbie