Created
May 10, 2012 14:40
-
-
Save xpathr/2653502 to your computer and use it in GitHub Desktop.
Image Formatter by wtdtan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
| <!-- | |
| BEGIN: optional | |
| if this is already included in another template, this block can be removed | |
| --> | |
| <xsl:template match="body//*"> | |
| <xsl:element name="{name()}"> | |
| <xsl:apply-templates select="* | @* | text()"/> | |
| </xsl:element> | |
| </xsl:template> | |
| <xsl:template match="body//@*"> | |
| <xsl:attribute name="{name(.)}"> | |
| <xsl:value-of select="."/> | |
| </xsl:attribute> | |
| </xsl:template> | |
| <!-- | |
| END: optional | |
| --> | |
| <!-- | |
| this template assumes this information: | |
| 1. <post-images> is a node within the returned xml | |
| 2. images can be given dimensions in 1 of 2 ways: | |
| 1. via drop down menu with output set to ###x### ie. 150x75 | |
| 2. two inputs, one for width, one for height | |
| --> | |
| <xsl:template match="@src" name="img-formatter" priority="1"> | |
| <xsl:param name="crop-mode" select="2" /> | |
| <xsl:param name="w"> | |
| <xsl:choose> | |
| <xsl:when test="$img-val = //post-images/post/entry/image/filename"> | |
| <xsl:choose> | |
| <xsl:when test="//post-images/post/entry[image/filename = $img-val]/size/item != '0x0'"> | |
| <xsl:value-of select="substring-before(//post-images/post/entry[image/filename = $img-val]/size/item, 'x')" /> | |
| </xsl:when> | |
| <xsl:when test="//post-images/post/entry[image/filename = $img-val]/width"> | |
| <xsl:value-of select="//post-images/post/entry[image/filename = $img-val]/width" /> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="450" /> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="450" /> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:param> | |
| <xsl:param name="h"> | |
| <xsl:choose> | |
| <xsl:when test="$img-val = //post-images/post/entry/image/filename"> | |
| <xsl:choose> | |
| <xsl:when test="//post-images/post/entry[image/filename = $img-val]/size/item != '0x0'"> | |
| <xsl:value-of select="substring-after(//post-images/post/entry[image/filename = $img-val]/size/item, 'x')" /> | |
| </xsl:when> | |
| <xsl:when test="//post-images/post/entry[image/filename = $img-val]/height"> | |
| <xsl:value-of select="//post-images/post/entry[image/filename = $img-val]/height" /> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="300" /> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="300" /> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:param> | |
| <xsl:param name="crop-pos" select="1" /> | |
| <xsl:param name="img-src" select="substring-after(., $workspace)" /> | |
| <xsl:attribute name="src"> | |
| <xsl:value-of select="concat($root, '/image/', $crop-mode, '/', $w, '/', $h, '/', $crop-pos, $img-src)"/> | |
| </xsl:attribute> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment