9 users online. Create an account or sign in to join them.Users
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):
<homepage-projects> <entry id="30"> <order>1</order> <project handle="linky">Linky</project> </entry> </homepage-projects> <homepage-thumbnails> <project link-id="30" link-handle="linky"> <entry id="40"> <project> <item handle="linky" id="30">Linky</item> </project> <thumb size="44 KB" path="/v3/images/projects/thumbs" type="image/jpeg"> <filename>linky_thumb-1263055122.jpg</filename> <meta creation="2010-01-09T11:38:42-05:00" width="155" height="75" /> </thumb> </entry> </project> </homepage-thumbnails>Now, when I have more than one post in each one, i want the correct
homepage-thumbnailsto show up with the correcthomepage-projectsentry. Here is the correspondingxslti’ve been trying to work with:<xsl:template match="data"> <xsl:apply-templates select="homepage-projects/entry"> <xsl:with-param name="id" select="@id" /> </xsl:apply-templates> </xsl:template> <xsl:template match="homepage-projects/entry"> <xsl:param name="id" /> <xsl:variable name="project-name" value="project/@handle" /> <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> <xsl:template match="homepage-thumbnails/project"> <img src="{$workspace}/{entry/thumb/@path}/{entry/thumb/filename}" alt="{entry/project/item}" /> </xsl:template>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.