Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Last active June 30, 2017 14:02
Show Gist options
  • Save andrewminton/2f5730d9b9522e326d9d51ae5a7cc1bb to your computer and use it in GitHub Desktop.
Save andrewminton/2f5730d9b9522e326d9d51ae5a7cc1bb to your computer and use it in GitHub Desktop.
<data>
<event-storage>
<group id="event">
<item id="International Bat Night - Bangers, Burgers &amp; Bats!">
<item id="event-id">5632</item>
<item id="adult-ticket">
<item id="quantity-chosen">4</item>
<item id="ticket-name">Adult Ticket</item>
<item id="ticket-id">5630</item>
<item id="ticket-price">20</item>
<item id="total">80</item>
</item>
<item id="child-ticket-over-7s-only">
<item id="quantity-chosen">2</item>
<item id="ticket-name">Child ticket (over 7's only)</item>
<item id="ticket-id">5631</item>
<item id="ticket-price">8.50</item>
<item id="total">17</item>
</item>
</item>
<item id="Introduction to Bushcraft">
<item id="event-id">5629</item>
<item id="introduction-to-bushcraft">
<item id="quantity-chosen">4</item>
<item id="ticket-name">Introduction to Bushcraft</item>
<item id="ticket-id">5628</item>
<item id="ticket-price">80</item>
<item id="total">320</item>
</item>
</item>
</group>
</event-storage>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl">
<xsl:output method="xml" indent="yes" />
<xsl:template match="data">
<!--<xsl:apply-templates select="//data/event-storage/group/item/item[@id !='event-id']" mode="tickets"/>-->
<xsl:variable name="total">
<xsl:for-each select="//data/event-storage/group/item/item[@id !='event-id']">
<xsl:call-template name="selects">
<xsl:with-param name="num">1</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="item[@id ='quantity-chosen']"/>
</xsl:with-param>
<xsl:with-param name="eventid" select="../item[@id='event-id']"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="exsl:node-set($total)" mode="ticket"/>
</xsl:template>
<!--<xsl:template match="//data/event-storage/group/item/item" mode="tickets">
<xsl:variable name="group">
<xsl:call-template name="selects">
<xsl:with-param name="num">1</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="item[@id ='quantity-chosen']"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates select="exsl:node-set($group)" mode="ticket"/>
</xsl:template> -->
<xsl:template name="selects">
<xsl:param name="num"/>
<xsl:param name="count"/>
<xsl:param name="eventid"/>
<xsl:if test="$num &lt;= $count">
<xsl:call-template name="tickets">
<xsl:with-param name="evid" select="$eventid"/>
</xsl:call-template>
<xsl:call-template name="selects">
<xsl:with-param name="num">
<xsl:value-of select="$num + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
<xsl:with-param name="eventid">
<xsl:value-of select="$eventid"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="tickets">
<xsl:param name="evid"/>
<xsl:copy>
<item id="evid"><xsl:value-of select="$evid"/></item>
<item id="quantity-chosen"><xsl:value-of select="item[@id='quantity-chosen']"/></item>
<item id="ticket-id"><xsl:value-of select="item[@id='ticket-id']"/></item>
</xsl:copy>
</xsl:template>
<xsl:template match="item" mode="ticket">
<div class="ticket">
<input name="tickets-sold[fields][{position() -1 }][ticket]" type="hidden" value="{item[@id='ticket-id']}"/>
<input name="tickets-sold[fields][{position() -1}][event]" type="hidden" value="{item[@id='evid']}"/>
<input name="tickets-sold[fields][{position() -1}][quantity]" type="hidden" value="{item[@id='quantity-chosen']}"/>
</div>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment