summaryrefslogtreecommitdiffstats
path: root/xslt
diff options
context:
space:
mode:
authorGravatar Martin Long <martin@longhome.co.uk>2014-12-09 23:24:47 +0000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-10 08:13:54 -0700
commitb462a8da3547202ba812ffcb265cbf29c9fb803f (patch)
treed65d832dae90845374bfa7d7f48382dde1a26d34 /xslt
parent3f34af4bed6214103cfa3d3483ae15c3d888b5c6 (diff)
downloadsubsurface-b462a8da3547202ba812ffcb265cbf29c9fb803f.tar.gz
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>
Diffstat (limited to 'xslt')
-rw-r--r--xslt/uddf-export.xslt76
1 files changed, 54 insertions, 22 deletions
diff --git a/xslt/uddf-export.xslt b/xslt/uddf-export.xslt
index 0d7f49b68..011b695d4 100644
--- a/xslt/uddf-export.xslt
+++ b/xslt/uddf-export.xslt
@@ -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">