6 users online. Create an account or sign in to join them.Users
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:
------8<--SNIP------ <xsl:template match="/"> <xsl:choose> <xsl:when test="$current-page = 'last'"> <xsl:variable name="article-element" select="'last-articles'"/> </xsl:when> <xsl:otherwise> <xsl:variable name="article-element" select="'article'"/> </xsl:otherwise> </xsl:choose> ------8<--SNIP------And I tried to use it this way:
------8<--SNIP------ <xsl:template name="get-article"> <xsl:for-each select="/data/$article-element/entry"> <div class="post span-9"> ------8<--SNIP------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 :)