This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsl issue for newbie

 
Rob Patterson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic