XSLT variable in XPath
This is an open discussion with 4 replies, filed under Troubleshooting.
Search
I may have just solved it with
*[entry[published]]
instead of the whole variable thing. Will update this when I'll have more information! #excited
F*** yes! :) Damn, that was satisfying.
My idea came from this link. I'll have to dive deeper into that. Some nice selector powers there :D
select="/data/*[name()=$article-element]/entry"
:-)
F*** yes! :) Damn, that was satisfying.
Hah, I think we all can relate to that. :-)
Create an account or sign in to comment.
Hi guys, I'm starting with XSLT & Co. and I've run into a problem.
I have two sections: call them "article" (because there's always only one) and "last-articles" (more of them). They've got the same "tree structure" inside, but the nodes have different names.
I want to render them in the same way, so instead of copying an utility and changing "article" for "last-articles", I tried to reuse my existing templates.
I've created a variable in my "master" XSL file:
And I tried to use it this way:
instead of doing something like: choose -> when $article-element = 'last-articles', <div with all 'last-articles' paths ..., otherwise <div with all 'article' paths.
But the XSLT Processor doesn't like me. (Even when I try to surround the $article-element with curly braces.)
How do you solve that? Should I think about it differently? Should I just stop being lazy and start manually copying these templates? (That's the only 100% possible way I see now) Wouldn't that be non-DRY? Couldn't PHP's XSLT engine use something like, I don't know, dynamic two-way processing?
Thanks in advance :)