New XSLT Utility: Magical JIT Resizer
This is an open discussion with 9 replies, filed under XSLT.
Search
@tmslnz - this utility looks great!!! Good work!
#win !
I'd like to see this template as a matched
one, not a named
one:
<xsl:apply-templates select="upload" mode="jit-magic"> <xsl:with-param name="mode" select="'fit'"/> <xsl:with-param name="w" select="400"/> <xsl:with-param name="h" select="400"/> </xsl:apply-template>
instead of
<xsl:call-template name="img"> <xsl:with-param name="upload" select="$upload"/> <xsl:with-param name="mode" select="'fit'"/> <xsl:with-param name="w" select="400"/> <xsl:with-param name="h" select="400"/> </xsl:call-template>
and
<xsl:apply-template select="'images.apple.com/home/images/mbp_hero20110224.png'" mode="jit-magic"> <xsl:with-param name="w" select="400"/> <xsl:with-param name="h" select="200"/> </xsl:apply-template>
instead of
<xsl:call-template name="img"> <xsl:with-param name="JITexternal" select="'images.apple.com/home/images/mbp_hero20110224.png'"/> <xsl:with-param name="w" select="400"/> <xsl:with-param name="h" select="200"/> </xsl:call-template>
That would be nice, good point.
Especially since I've never tried using <template select="'string'">
. Does it even work?
Although we'd only save one line and the interface would have to change quite a bit to have symmetry between the two modes: how would you put in dummy mode by just giving it h
and w
when upload = ' '
is used to determine the mode in that case?
UPDATE
I have pushed a new version to GitHub. It does matching now.
@phoque: how would you do <xsl:apply-templates select=" 'URLstring' ">
. Everywhere I look I see that the select
attribute in that context can only take XPaths.
@tmslnz
Everywhere I look I see that the select attribute in that context can only take XPaths.
Indeed.
Just use the call-template variant with "upload" param.
<xsl:call-template name="img"> <xsl:with-param name="upload" select="$url" /> </xsl:template>
I believe 'string'
a valid Xpath expression.
I really cannot figure how you would <xsl:apply-templates>
with a select=" 'String' "
expression.
While you are right in saying that string is a valid XPath expression, I believe that <xsl:apply-templates>
's select
attribute can only accept an expression that evaluates to a node-set.
Please, if I am wrong fix me up with an example.
@vladG: you cannot use upload
set to an external image URL at the moment, since I should be checking for valid filetype extensions (.jpg, .png) at the end of the string to determine if it's a node-set or an image URL, and at the moment I am not doing it.
However the current interface will use URLs passed by param JITexternal
so it would look like:
<xsl:call-template name="img"> <xsl:with-param name="JITexternal" select="'images.apple.com/home/images/mbp_hero20110224.png'"/> <xsl:with-param name="w" select="400"/> <xsl:with-param name="h" select="200"/> </xsl:call-template>
You're going to use a normal expression anyways (the URL is in the XML, not the XSL). So I'm thinking of two match
es:
A template that matches nodes and attributes and will try to use .
as the external URL:
<xsl:template match="* | *@" mode="jit" />
Another one that matches upload-fields (recognises them by the path
attribute)
<xsl:template match="*[@path]" mode="jit" />
You could then do stuff like apply to a upload field:
<xsl:apply-templates select="uploadfield" mode="jit" />
apply to a text-field containing an URL:
<xsl:apply-templates select="textfield" mode="jit" />
or apply it to the src
attribute of img
tags (i.e. using the Ninja utilities):
<xsl:apply-templates select="img/@src" mode="jit" />
The utility's upload
is already using .
as a default param. So if you use it with recursion or any other match
method it's going to use whatever you pointed it to as its upload
value.
My question was referring to your first comment, where you suggested to use <xsl:apply-templates select=" 'images.apple.com/home/images/mbp_hero20110224.png' " mode="jit">…
.
Note the string value passed to the select statement. Unless I'm at a complete impasse, I don't think that'll evaluate.
Create an account or sign in to comment.
Hi all,
I posted a new JIT resizing utility, written from scratch and merging most of the functionality found in the other JIT utils already available on this site and some more.
http://getsymphony.com/download/xslt-utilities/view/62666/ https://github.com/tmslnz/Magical-JIT-Resizer
I tested it a bit, but it's still very fresh so please feel free to comment/contribute to it.
I tried to keep the code as modular as possible, so to make it easier to add further functionality in the future.
Also, the "interface" is very minimal, with potentially zero required params. XSLT is already quite verbose...
TODOs:
Note to the admins
I kept receiving this error when posting:
Fatal error: Exception thrown without a stack frame in Unknown on line 0
...and now there's three posts for the same thing. Please keep only
http://getsymphony.com/download/xslt-utilities/view/62666/
Best, t