Reputation: 16057
This is a "best design approach" question more than a coding question. I'm looking for the best approach to filtering data in XSLT. I have a blog which is generated from XML, XSLTand CSS. Each blog post falls under a category - Week 1, Week 2 or Week 3.
At the moment, I'm displaying all the categories on the side. When I click WEEK1, I want to show only posts from Week 1. Is this any way to do this without having an XML file for each week?
As a sideline... this is a demo of what XSLT can do. Something like php would have been much better suited for the job, but this needs to be done with XSLT/HTML/JavaScript/CSS.
If the question is not clear, please ask and I will do my best to rephrase it.
Upvotes: 2
Views: 148
Reputation: 11561
This is where XLink would come in handy, unfortunately browser support is still pathetic.
What i would try is pre-processing the XML with JS and XPath, so it only contains the week you want. Then send only that XML into the XSLTProcessor()
, so it'll only put out those. You may have to assemble the whole HTML document outside of XSL then though - not sure.
You could also send XML parameters as parameters into the processor and use them in your transformation.
But in the end, it's still inefficient to send the whole XML over the wire, if you're only going to show a fraction of it. So, a server-side solution to generate only the XML that's actually needed would be better.
Last but not least, maybe have a look at Saxon-CE.
Upvotes: 0
Reputation: 187
If you want demonstrate what xslt can do, perhaps a simple xpath query like //WEEKS[.="WEEK1"] for example can be sufficient
Upvotes: 0
Reputation: 117354
There may be many approaches.
The fastest should be: Give every post a className related to the week(e.g. post week1
,post week2
, etc.)
When you click on a link on the side, give the common anchestor of all posts also a class, related to the clicked Week, e.g. posts week1
All you need now is a little bit of css:
.posts .post{
display:none;
}
.posts.week1 .post.week1,
.posts.week2 .post.week2,
.posts.week3 .post.week3{
display:block;
}
Upvotes: 1