Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Created June 29, 2017 14:09
Show Gist options
  • Save andrewminton/c6efe4068d54c58694c5bea727a52019 to your computer and use it in GitHub Desktop.
Save andrewminton/c6efe4068d54c58694c5bea727a52019 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" version="1.0">
<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:template>
<xsl:template match="//data/event-storage/group/item/item" mode="tickets">
<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:template>
<xsl:template name="selects">
<xsl:param name="num"/>
<xsl:param name="count"/>
<xsl:if test="$num <= $count">
<xsl:call-template name="tickets">
<xsl:with-param name="number"><xsl:value-of select="$num + 1"/></xsl:with-param>
</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:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="tickets">
<div class="ticket">
<input name="tickets-sold[fields][{position()}][ticket]" type="hidden" value="{item[@id='ticket-id']}"/>
<input name="tickets-sold[fields][{position()}][event]" type="hidden" value="{../item[@id ='event-id']}"/>
<input name="tickets-sold[fields][{position()}][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