XSLT and XPath noob help.
This is an open discussion with 7 replies, filed under XSLT.
Search
Hi dallaspeters,
I believe this is what you are looking for, it’s crude, but it should work:
<a href="{thumbnail/item[1]/@path}/{thumbnail/item[1]/filename}" rel="prettyPhoto[{project-title@handle}]">QuickLook</a> ... <img src="{thumbnail/item[1]/@path}/{thumbnail/item[1]/filename}" rel="prettyPhoto[{project-title@handle}]">
When you need to reference something into an attribute, there are a few methods of doing this. The first is the example I’ve put above (which you kind of already used for your H3 tags) - essentially you put your xpath statement into curly braces {} letting xslt know you want it to execute the xpath call.
When you start to get to a point where you need to call the same thing over again you may want to store that call in a param or a variable and then call it into the curly braces. A typical example is {$root} which you’ve probably seen a few times now.
Lastly, if you need to manipulate multiple attributes you may want to consider combining the above methods into something like this:
<img> <xsl:variable name="pathtoimage" select="thumbnail/item[1]/@path"/> <xsl:attribute name="src"><xsl:value-of select="$pathtoimage"/><xsl:value-of select="thumbnail/item[1]/filename"/></xsl:attribute> </img>
I hope this was what you were looking for.
I’ve also used this prettyPhoto on a Symphony project, so I know what you’re aiming for http://www.amandadredge.co.uk
Thanks for getting back. Not sure I’m doing it right. (though rather than ‘thumbnail’ I’m after ‘project-images’)
I have:
<p class="quicklook"> <a class="magnify" href="{project-images/item[1]/@path}/{project-images/item[1]/filename}" rel="prettyPhoto">QuickLook</a> </p>
Which is outputting this:
<a rel="prettyPhoto" href="/" class="magnify">QuickLook</a>
And then when I try to use the rel="prettyPhoto[{project-title@handle}]"
it gives me:
- XSLTProcessor::importStylesheet(): Invalid expression
- XSLTProcessor::importStylesheet(): Attribute ‘rel’: Failed to compile the expression ‘project-title@handle’ in the AVT.
- XSLTProcessor::transformToXml(): No stylesheet associated to this object
Sure I’m doing something wrong.
that first output didn’t take in the forum.
<a rel="prettyPhoto" href="/" class="magnify">QuickLook</a>
My first guess would be
{project-title/@handle}
<a class="magnify" href="{$root}/workspace/{project-images/item[1]/image/@path}/{project-images/item[1]/image/filename}" rel="prettyPhoto[{project-title/@handle}]">Quicklook</a>
worked, but seems like a really clunky way of doing it eh?
What ended up working:
<p class="quicklook"> <a class="magnify" href="workspace{project-images/item[position() = 1]/image/@path}/{project-images/item[position() = 1]/image/filename}" rel="prettyPhoto[{project-title/@handle}]">Quicklook</a> </p> <div class="hidden"> <xsl:for-each select="project-images/item[position() > 1]"> <a> <xsl:attribute name="href">workspace/uploads/<xsl:value-of select="image/filename"/> </xsl:attribute> <xsl:attribute name="rel">prettyPhoto[<xsl:value-of select="../../project-title/@handle"/>]</xsl:attribute> <img> <xsl:attribute name="src">workspace/uploads/<xsl:value-of select="image/filename"/> </xsl:attribute> </img> </a> </xsl:for-each> </div>
Feels pretty sloppy. For some reason I have to put workspace in there. Not sure if my get-images.xsl is messing with the urls of my images. I’m also using Mediathek.
you can tighten up the xsl with concat
:
<a> <xsl:attribute name="href" select="concat($workspace, '/uploads/', image/filename)" /> <xsl:attribute name="rel" select="concat('prettyPhoto[',../../project-title/@handle, ']')" /> <img> <xsl:attribute name="src" select="concat($workspace, '/uploads/', image/filename)" /> </img> </a>
another approach is doing it all inline:
<a href="{$workspace}/uploads/{image/filename}" rel="prettyPhoto[{../../project-title/@handle}]> <img src="{$workspace}/uploads/{image/filename}" /> </a>
Create an account or sign in to comment.
Ok. Bit of a noob question here but hoping someone can help me out as I’m making spaghetti out of my brain on this.
Here is the XML that I am out putting:
Here is my utility (get-project.xsl):
Let me know if that’s not clear enough. Its obviously not to me. ;) I can post more or help out any way possible. Thanks if anyone takes a look at this.