Separate out buddies into individual entities when exporting to UDDF.

Part of a series bringing UDDF export closer to the UDDF standard, as
per www.uddf.org.

Currently when exporting to UDDF buddy entities are created
one-per-unique-combination. This means that a group of buddies on a dive
are exported as a single buddy, with the names comma separated.

This patch identifies all unique buddies, whether used independently or
along with other buddies on a dive. They are then linked independently
on each profile.

It also uses the UDDF standard <link ref=""> instead of
<buddy_ref ref="">

Signed-off-by: Marton Long <martin@longhome.co.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Martin Long 2014-12-09 23:24:47 +00:00 committed by Dirk Hohndel
parent 3f34af4bed
commit b462a8da35

View file

@ -1,4 +1,5 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xt="http://www.jclark.com/xt"
extension-element-prefixes="xt" version="1.0">
<xsl:include href="commonTemplates.xsl"/>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
@ -54,8 +55,27 @@
</xsl:for-each>
</equipment>
</owner>
<xsl:apply-templates select="//buddy"/>
<xsl:variable name="buddylist">
<xsl:for-each select="//buddy">
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="." />
<xsl:with-param name="delim" select="', '" />
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xt:node-set($buddylist)/token[generate-id() = generate-id(key('tokenkey', .)[1])]">
<xsl:sort select="." />
<buddy>
<xsl:attribute name="id">
<xsl:value-of select="."/>
</xsl:attribute>
<personal>
<first_name>
<xsl:value-of select="."/>
</first_name>
</personal>
</buddy>
</xsl:for-each>
</diver>
<xsl:apply-templates select="//location"/>
@ -121,20 +141,23 @@
</uddf>
</xsl:template>
<xsl:key name="buddy" match="buddy" use="."/>
<xsl:template match="buddy">
<xsl:if test="generate-id() = generate-id(key('buddy', normalize-space(.)))">
<buddy>
<xsl:attribute name="id">
<xsl:value-of select="."/>
</xsl:attribute>
<personal>
<first_name>
<xsl:value-of select="."/>
</first_name>
</personal>
</buddy>
</xsl:if>
<xsl:key name="tokenkey" match="token" use="." />
<xsl:template name="tokenize">
<xsl:param name="string" />
<xsl:param name="delim" />
<xsl:choose>
<xsl:when test="contains($string, $delim)">
<token><xsl:value-of select="substring-before($string, $delim)" /></token>
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="substring-after($string,$delim)" />
<xsl:with-param name="delim" select="$delim" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<token><xsl:value-of select="$string" /></token>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:key name="location" match="location" use="."/>
@ -179,13 +202,22 @@
<divenumber>
<xsl:value-of select="./@number"/>
</divenumber>
<xsl:if test="buddy != ''">
<buddy_ref>
<xsl:variable name="buddylist">
<xsl:for-each select="buddy">
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="." />
<xsl:with-param name="delim" select="', '" />
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xt:node-set($buddylist)/token[generate-id() = generate-id(key('tokenkey', .)[1])]">
<xsl:sort select="." />
<link>
<xsl:attribute name="ref">
<xsl:value-of select="buddy"/>
<xsl:value-of select="."/>
</xsl:attribute>
</buddy_ref>
</xsl:if>
</link>
</xsl:for-each>
<xsl:if test="location != ''">
<dive_site_ref>
<xsl:attribute name="ref">