Skip to content

Instantly share code, notes, and snippets.

Created January 16, 2013 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4546630 to your computer and use it in GitHub Desktop.
Save anonymous/4546630 to your computer and use it in GitHub Desktop.
<data>
<aspectratios>
<item name="onebyone">1</item>
<item name="onebytwo">0.5</item>
<item name="onebythree">0.33333</item>
<item name="twobyone">2</item>
<item name="twobythree">0.66667</item>
<item name="twobyfive">0.4</item>
<item name="threebyone">3</item>
<item name="threebytwo">1.5</item>
<item name="threebyfive">0.6</item>
<item name="fivebytwo">2.5</item>
<item name="fivebythree">1.66667</item>
</aspectratios>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:call-template name="find-nearest-value">
<xsl:with-param name="list" select="aspectratios"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="find-nearest-value">
<xsl:param name="value" select="0.8"/>
<xsl:param name="list"/>
<xsl:for-each select="list/item">
<xsl:sort select="(. - $value) * not(0 > . - $value ) - (. - $value) * (0 > . - $value)"/>
<xsl:if test="position() = 1">
<xsl:value-of select="@name"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment