XPath issue
This is an open discussion with 4 replies, filed under XSLT.
Search
Line 3 of your XSLT can’t result in any ID since the template matches the data
node. You should try it in a different way: From the template matching your projects’ entry
nodes you should pass the project ID to a second template matching the thumbnail project
nodes.
thanks michael - i can never remember the correct way to get a select
value for xsl:with-param
when using xpath.
pass the project ID to a second template matching the thumbnail project nodes.
isn’t that what this line does:
<xsl:apply-templates select="../../homepage-thumbnails/project[$id=@link-id]" />
that is assuming if the $id
value is correct.
Shouldn’t this work?
<xsl:template match="data"> <xsl:apply-templates select="homepage-projects/entry" /> </xsl:template> <xsl:template match="homepage-projects/entry"> <xsl:variable name="thumb" select="/data/homepage-thumbnails/project[@link-id = @id]" /> <div class="project_thumb"> <a class="no_bg" href="{$root}/projects/{@id}/{project/@handle}/" title="{project}"> <img src="{$workspace}/{$thumb/entry/thumb/@path}/{$thumb/entry/thumb/filename}" alt="{$thumb/entry/project/item}" /> <span><xsl:value-of select="project" /></span> </a> </div> </xsl:template>
@nils, i run into the same issues of using your template where the data is not selected correctly, thus resulting in missing images.
the issue seemed to be that I was trying to pass in the $id
. i changed it around so that i no longer passed that value in and instead made a xsl:variable
inside my homepage-projects/entry
node with the id
value instead.
<xsl:template match="homepage-projects/entry"> <xsl:variable name="id" select="@id" /> <div class="project_thumb"> <a class="no_bg" href="{$root}/projects/{@id}/{project/@handle}/" title="{project}"> <xsl:apply-templates select="../../homepage-thumbnails/project[$id=@link-id]" /> <span><xsl:value-of select="project" /></span> </a> </div> </xsl:template>
Create an account or sign in to comment.
I have two sibling nodes, each of which contain information about a post (truncated version):
Now, when I have more than one post in each one, i want the correct
homepage-thumbnails
to show up with the correcthomepage-projects
entry. Here is the correspondingxslt
i’ve been trying to work with:However, the $id param in the homepage-projects/entry template is always blank even when trying to pass in the id param with the
apply-templates
. This in turn makes my xpath filtering for the image incorrect and results in no image.any clues?
thanks in advance.