Skip to content

Instantly share code, notes, and snippets.

@s-e
Created March 6, 2013 12:01
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 s-e/5098848 to your computer and use it in GitHub Desktop.
Save s-e/5098848 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<data>
<products>
<entry id="1">
<name>Test</name>
<public-price>10.00</public-price>
<trade-price>8.00</trade-price>
</entry>
<entry id="2">
<name>Test</name>
<public-price>10.00</public-price>
<trade-price>8.00</trade-price>
</entry>
<entry id="3">
<name>Test</name>
<public-price>10.00</public-price>
<trade-price>8.00</trade-price>
</entry>
<entry id="4">
<name>Test</name>
<public-price>10.00</public-price>
<trade-price>8.00</trade-price>
</entry>
<entry id="5">
<name>Test</name>
<public-price>10.00</public-price>
<trade-price>8.00</trade-price>
</entry>
</products>
<prices>
<entry id="6">
<product>
<item id="1">Test</item>
</product>
<public-price>15.00</public-price>
<trade-price>14.00</trade-price>
</entry>
<entry id="7">
<product>
<item id="2">Test</item>
</product>
<public-price>12.00</public-price>
<trade-price>11.00</trade-price>
</entry>
<entry id="8">
<product>
<item id="3">Test</item>
</product>
<public-price>18.00</public-price>
<trade-price>15.00</trade-price>
</entry>
</prices>
<offers>
<entry id="9">
<product>
<item id="1">Test</item>
</product>
<public-offer-price>5.00</public-offer-price>
<trade-offer-price>4.00</trade-offer-price>
</entry>
<entry id="10">
<product>
<item id="3">Test</item>
</product>
<public-offer-price>6.00</public-offer-price>
<trade-offer-price>5.00</trade-offer-price>
</entry>
<entry id="11">
<product>
<item id="4">Test</item>
</product>
<public-offer-price>7.00</public-offer-price>
<trade-offer-price>6.00</trade-offer-price>
</entry>
</offers>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common">
<xsl:template match="/">
<xsl:variable name="offer-merged-products">
<xsl:apply-templates select="data/products/entry" mode="merge-prices" />
</xsl:variable>
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<xsl:choose>
<xsl:when test="$user-type = 'trade'">
<xsl:apply-templates select="exsl:node-set($offer-merged-products)/product" mode="display">
<xsl:sort select="exsl:node-set($offer-combined-products)/trade-price" data-type="number" order="descending" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$user-type = 'public'">
<xsl:apply-templates select="exsl:node-set($offer-merged-products)/product" mode="display">
<xsl:sort select="exsl:node-set($offer-merged-products)/public-price" data-type="number" order="descending" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<tr class="error"><td colspan="2">Unknown user type!</td></tr>
</xsl:otherwise>
</xsl:choose>
</tbody>
</table>
</xsl:template>
<xsl:template match="data/products/entry" mode="merge-prices">
<xsl:variable name="$current-product-id" select="@id" />
<xsl:variable name="$offers-node" select="/data/offers" />
<product>
<name><xsl:value-of select="name"/></name>
<xsl:choose>
<xsl:when test="$offers-node/entry[product/item/@id=$current-product-id]">
<public-price>
<xsl:value-of select="$offers-node/entry[product/item/@id=$current-product-id]/public-offer-price" />
</public-price>
<trade-price>
<xsl:value-of select="$offers-node/entry[product/item/@id=$current-product-id]/trade-offer-price" />
</trade-price>
</xsl:when>
<xsl:otherwise>
<public-price><xsl:value-of select="public-price" /></public-price>
<trade-price><xsl:value-of select="trade-price" /></trade-price>
</xsl:otherwise>
</xsl:choose>
</product>
</xsl:template>
<xsl:template match="product" mode="display">
<tr>
<td><xsl:value-of select="name"/></td>
<td>
<xsl:choose>
<xsl:when test="$user-type = 'trade'">
<xsl:value-of select="trade-price"/>
</xsl:when>
<xsl:when test="$user-type = 'public'">
<xsl:value-of select="public-price"/>
</xsl:when>
<xsl:otherwise />
</xsl:choose>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment