1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
<?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" encoding="UTF-8" indent="yes"/>
<!-- XSL to convert XML GDCM2 data dictionay into
dcm4che data dictionary
Checked against:
http://dcm4che.svn.sourceforge.net/viewvc/dcm4che/dcm4che2/trunk/dcm4che-core/src/xml/dictionary.xml
-->
<!--
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
-->
<!--life saver xsl script found at:
http://www.thescripts.com/forum/thread86881.html
-->
<xsl:template name="upperCase">
<xsl:param name="textToTransform"/>
<xsl:variable name="head">
<xsl:choose>
<xsl:when test="contains($textToTransform, ' ')">
<xsl:value-of select="substring-before($textToTransform, ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$textToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="tail" select="substring-after($textToTransform, ' ')"/>
<xsl:variable name="firstTransform" select="concat(translate(substring($head, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), substring($head, 2))"/>
<xsl:choose>
<xsl:when test="$tail">
<xsl:value-of select="$firstTransform"/>
<xsl:call-template name="upperCase">
<xsl:with-param name="textToTransform" select="$tail"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$firstTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
http://www.dpawson.co.uk/xsl/sect2/replace.html
-->
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="makeKeyword">
<xsl:param name="textToTransform"/>
<xsl:variable name="apos">'</xsl:variable>
<!--translating an apostrophe is a pain ... better solution ? -->
<xsl:variable name="description_apos3">
<!--xsl:value-of select="translate($textToTransform, $apos, '')"/-->
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$textToTransform"/>
<xsl:with-param name="replace">De-identification</xsl:with-param>
<xsl:with-param name="with" select="'Deidentification'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="description_apos2">
<!--xsl:value-of select="translate($textToTransform, $apos, '')"/-->
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$description_apos3"/>
<xsl:with-param name="replace">'s</xsl:with-param>
<xsl:with-param name="with" select="' '"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="description_apos">
<!--xsl:value-of select="translate($textToTransform, $apos, '')"/-->
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$description_apos2"/>
<xsl:with-param name="replace">Sub-operations</xsl:with-param>
<xsl:with-param name="with" select="'Suboperations'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="description_dash2">
<xsl:value-of select="translate($description_apos,'-/',' ')"/>
</xsl:variable>
<xsl:variable name="description_dash">
<xsl:value-of select="translate($description_dash2,$apos,'')"/>
</xsl:variable>
<xsl:variable name="description_cap">
<xsl:call-template name="upperCase">
<xsl:with-param name="textToTransform" select="normalize-space($description_dash)"/>
</xsl:call-template>
</xsl:variable>
<!-- remove remaining extra character -->
<xsl:value-of select="translate($description_cap,'(),','')"/>
</xsl:template>
<!-- The main template that loop over all dict/entry -->
<xsl:template match="/">
<dictionary tagclass="org.dcm4che2.data.Tag">
<xsl:text>
</xsl:text>
<xsl:for-each select="dicts/dict/entry">
<xsl:sort select="@group"/>
<xsl:sort select="@element"/>
<xsl:variable name="description_cap">
</xsl:variable>
<xsl:variable name="keyword">
<xsl:call-template name="makeKeyword">
<xsl:with-param name="textToTransform" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="group">
<xsl:value-of select="translate(@group,'abcdef','ABCDEF')"/>
</xsl:variable>
<xsl:variable name="element">
<xsl:value-of select="translate(@element,'abcdef','ABCDEF')"/>
</xsl:variable>
<xsl:variable name="vr">
<xsl:value-of select="translate(@vr,'_','|')"/>
</xsl:variable>
<xsl:variable name="retired">
<xsl:choose>
<xsl:when test="@retired = 'true'">
<xsl:text>RET</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<element tag="{$group}{$element}" keyword="{$keyword}" vr="{$vr}" vm="{@vm}" ret="{$retired}"><xsl:value-of select="@name"/></element>
<xsl:text>
</xsl:text>
</xsl:for-each>
</dictionary>
</xsl:template>
</xsl:stylesheet>
|