Skip to content

Instantly share code, notes, and snippets.

@dfeyer
Created March 28, 2013 23:52
Show Gist options
  • Save dfeyer/5267776 to your computer and use it in GitHub Desktop.
Save dfeyer/5267776 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"
version='1.0'
encoding='UTF-8'
indent="yes"/>
<xsl:template name="badge">
<xsl:if test="status = 'approved'">
<xsl:variable name="person_id" select="person/@id"/>
<xsl:variable name="person_xml" select="concat('http://www.eventival.eu/festival/2013/en/ws/APIKEY/people/', $person_id, '.xml')"/>
<xsl:variable name="person_document" select="document($person_xml, /)"/>
<xsl:variable name="primary_business_card" select="$person_document/person/business_cards/business_card[1]"/>
<badge>
<external_identifier>
<xsl:value-of select="./@id"/>
</external_identifier>
<cancelled>
<xsl:value-of select="normalize-space(cancelled)"/>
</cancelled>
<status>
<xsl:value-of select="normalize-space(status)"/>
</status>
<type>
<xsl:value-of select="normalize-space(badge_type/name)"/>
</type>
<type_category>
<xsl:value-of select="normalize-space(badge_type_category/name)"/>
</type_category>
<name>
<xsl:value-of select="normalize-space(concat(person/name, ' ', person/surname))"/>
</name>
<industry>
<xsl:value-of select="normalize-space($person_document/person/eventival_categorization/professions/profession/industry)"/>
</industry>
<section>
<xsl:value-of select="normalize-space($person_document/person/eventival_categorization/professions/profession/section)"/>
</section>
<profession>
<xsl:value-of select="normalize-space($person_document/person/eventival_categorization/professions/profession/profession)"/>
</profession>
<person>
<id>
<xsl:value-of select="normalize-space($person_document/person/ids/internal_id)"/>
</id>
<name>
<xsl:value-of select="normalize-space($person_document/person/names/name_first)"/>
</name>
<surname>
<xsl:value-of select="normalize-space($person_document/person/names/name_last)"/>
</surname>
<company>
<xsl:value-of select="normalize-space($primary_business_card/company/full_name)"/>
</company>
<street>
<xsl:value-of select="normalize-space($primary_business_card/address/line1)"/>
</street>
<street_additional>
<xsl:value-of select="normalize-space($primary_business_card/address/line1)"/>
</street_additional>
<postal_code>
<xsl:value-of select="normalize-space($primary_business_card/address/postcode)"/>
</postal_code>
<locality>
<xsl:value-of select="normalize-space($primary_business_card/address/city)"/>
</locality>
<xsl:choose>
<xsl:when test="count($primary_business_card/business_card/address/country[1]/code)">
<country>
<code>
<xsl:value-of select="normalize-space($primary_business_card/business_card/address/country[1]/code)"/>
</code>
<human_readable>
<xsl:value-of select="normalize-space($primary_business_card/business_card/address/country[1]/human_readable)"/>
</human_readable>
</country>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="count($primary_business_card/emails/email)">
<emails>
<xsl:for-each select="$primary_business_card/emails">
<email_address>
<address>
<xsl:value-of select="normalize-space(email/email)"/>
</address>
</email_address>
</xsl:for-each>
</emails>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="count($primary_business_card/phones/phone)">
<phones>
<xsl:for-each select="$primary_business_card/phones">
<phone_number>
<number>
<xsl:choose>
<xsl:when test="phone/idd and phone/phone">
<xsl:value-of select="normalize-space(concat('+', normalize-space(phone/idd), ' ', normalize-space(phone/phone)))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(phone/phone)"/>
</xsl:otherwise>
</xsl:choose>
</number>
</phone_number>
</xsl:for-each>
</phones>
</xsl:when>
</xsl:choose>
<photo>
<xsl:value-of select="normalize-space($person_document/person/photos[1]/photo)"/>
</photo>
</person>
<groups>
<xsl:for-each select="person/groups/group_combination">
<group>
<maingroup>
<xsl:value-of select="normalize-space(group/name)"/>
</maingroup>
<subgroup>
<xsl:value-of select="normalize-space(subgroup/name)"/>
</subgroup>
</group>
</xsl:for-each>
</groups>
</badge>
</xsl:if>
</xsl:template>
<xsl:template match="//badge">
<xsl:call-template name="badge"/>
</xsl:template>
<!-- Copy everything else -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment