A natural progression of working with Umbraco for us is now building super flexible (and hopefully smart!) XSLT macro's which mean we can roll out developments faster. This works around the fact we use grids for our projects.
It all works nicely, however I was wondering if anyone had any idea's on how to refactor this code.
Look at the $ModuleWidth and get the correct grid for it.
--
The first code snippet is how in a weird Laurence world this would work, (but can't!)
Indeed, but is there a way of writing <xsl:value-of select="$grid_$moduleWidth"/> as a variable its self, which then produces the correct output. Having to use a <xsl:choose> isn't really ideal as it ties you down into that array, (and plus its visually quite large!)
Variable Mashups
Hi there,
A natural progression of working with Umbraco for us is now building super flexible (and hopefully smart!) XSLT macro's which mean we can roll out developments faster. This works around the fact we use grids for our projects.
It all works nicely, however I was wondering if anyone had any idea's on how to refactor this code.
Look at the $ModuleWidth and get the correct grid for it.
--
The first code snippet is how in a weird Laurence world this would work, (but can't!)
Get the value of $grid_(x)
Where x = $moduleWidth (which is an integer)
<img> <xsl:attribute name="src"> <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text> <xsl:value-of select="umbraco.library:GetMedia($media,'1')/data [@alias = 'mediaCrops']//crop[@name = 'Portrait']/@url"/> <!-- This code needs refactoring --> <xsl:text>&width=</xsl:text> <xsl:value-of select="$grid_$moduleWidth"/>
This is the code which does however work;
Thanks in advance!
Hope this isn't a dumb problem, but more of an interesting one! It's getting me thinking! Laurie
<xsl:value-of select="$grid_$moduleWidth"/> will not work as $grid_$moduleWidth is not a valid xpath expression.
You can rewrite the <xsl:choose to an xslt extension if you wish to compress the visual size of it.
Or perhaps just make your own version of GetMedia which takes an extra parameter and returns the url with the correct width.
/Harald
Indeed, but is there a way of writing <xsl:value-of select="$grid_$moduleWidth"/> as a variable its self, which then produces the correct output. Having to use a <xsl:choose> isn't really ideal as it ties you down into that array, (and plus its visually quite large!)
Maybe I'm just being anal! Lau
Hi Lau,
Harald's right - store the array using an XSLT extension, I think dynamic evaluation of an expression is a bit beyond XSLT's basic capabilities.
Benjamin
Hi Laurence,
You should be able to use a variable with XML content for this - just need to convert it to a nodeset before you can XPath your way into it:
/Chriztian
Beautiful solution Chriztian (: Thank-you, Laurie
is working on a reply...