- Timestamp:
- 09/19/12 10:32:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SMC/trunk/SMC/src/scripts/smc_functions.xsl
r1607 r2231 1 1 <?xml version="1.0"?> 2 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 2 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 3 3 xmlns:my="myFunctions"> 4 4 … … 10 10 --> 11 11 12 <!-- did not work 13 <xsl:variable name="all-terms-nested" select="doc('file:/C:/Users/m/3lingua/clarin/CMDI/_repo2/SMC/data/cmd-terms-nested.xml')" /> 14 <xsl:key name="term-name" match="//Term" use="@name"></xsl:key> 15 --> 12 16 <!-- 13 17 @param profiles - list of <profileDescription> … … 15 19 <xsl:function name="my:profiles2termsets" > 16 20 <xsl:param name="profiles"/> 21 <xsl:param name="nested"/> 17 22 18 23 <Termsets count="{count($profiles)}"> … … 22 27 23 28 <!-- flattening the structure! --> 29 <xsl:choose> 30 <xsl:when test="$nested"> 31 <xsl:apply-templates select="CMD_ComponentSpec/CMD_Component" mode="make-term"> 32 <xsl:with-param name="nested" select="$nested"></xsl:with-param> 33 </xsl:apply-templates> 34 </xsl:when> 35 <xsl:otherwise> 36 <xsl:apply-templates select=".//CMD_Component|.//CMD_Element" mode="make-term"> 37 <xsl:with-param name="nested" select="$nested"></xsl:with-param> 38 </xsl:apply-templates> 39 </xsl:otherwise> 40 </xsl:choose> 41 42 <!-- 24 43 <xsl:for-each select=".//CMD_Component|.//CMD_Element" > 25 <xsl:variable name="context" select="my:context(.)" />44 <xsl:variable name="context" select="my:context(.)" /> 26 45 27 46 <xsl:variable name="type" select="name()" /> … … 31 50 <xsl:value-of select="@ComponentId" /> 32 51 </xsl:when> 33 <!- - top component = profile -->52 <!-\- top component = profile -\-> 34 53 <xsl:when test="not(exists(ancestor::CMD_Component))"> 35 54 <xsl:value-of select="$profile_id" /> … … 45 64 parent="{ancestor::CMD_Component[1]/@name}" path="{$context}" 46 65 > 47 <!- - <xsl:copy-of select="." /> -->66 <!-\- <xsl:copy-of select="." /> -\-> 48 67 </Term> 49 </xsl:for-each>50 </Termset>68 </xsl:for-each> 69 --> </Termset> 51 70 </xsl:for-each> 52 71 </Termsets> 53 72 </xsl:function> 73 74 <xsl:template match="CMD_Component|CMD_Element" mode="make-term"> 75 <xsl:param name="nested" select="true()"></xsl:param> 76 <xsl:variable name="context" select="my:context(.)" /> 77 78 <xsl:variable name="type" select="name()" /> 79 <xsl:variable name="id" > 80 <xsl:choose> 81 <xsl:when test="@ComponentId"> 82 <xsl:value-of select="@ComponentId" /> 83 </xsl:when> 84 <!-- top component = profile --> 85 <xsl:when test="not(exists(ancestor::CMD_Component))"> 86 <xsl:value-of select="(ancestor::profileDescription/id, ancestor::CMD_ComponentSpec/Header/ID)[1]" /> 87 </xsl:when> 88 <xsl:otherwise> 89 <xsl:value-of select="ancestor::CMD_Component[@ComponentId][1]/@ComponentId" /><xsl:text>#</xsl:text> 90 <xsl:for-each select="ancestor::CMD_Component[not(descendant-or-self::CMD_Component[@ComponentId])]" > 91 <xsl:value-of select="@name" />.</xsl:for-each><xsl:value-of select="@name" /> 92 </xsl:otherwise> 93 </xsl:choose> 94 </xsl:variable> 95 96 <Term type="{$type}" name="{@name}" datcat="{@ConceptLink}" id="{$id}" elem="{@name}" 97 parent="{ancestor::CMD_Component[1]/@name}" path="{$context}" 98 > 99 <!-- <xsl:copy-of select="." /> --> 100 <xsl:if test="$nested"> 101 <xsl:apply-templates select="CMD_Component|CMD_Element" mode="make-term"> 102 <xsl:with-param name="nested" select="$nested"></xsl:with-param> 103 </xsl:apply-templates> 104 </xsl:if> 105 </Term> 106 </xsl:template> 54 107 55 108 <!-- … … 93 146 94 147 148 <xsl:function name="my:diffContext" > 149 <xsl:param name="c1" /> 150 <xsl:param name="c2" /> 151 <!-- <xsl:message>C1:<xsl:copy-of select="count($c1/ancestor::Term/@name)" /></xsl:message> 152 <xsl:message><xsl:value-of select="$c1/ancestor::Term/@name" /></xsl:message> 153 <xsl:message>C2:<xsl:value-of select="$c2/ancestor::Term/@name" /></xsl:message> 154 --> 155 <!-- <xsl:value-of select="($c1/ancestor::Term/@name except $c2/ancestor::Term/@name)[last()]" />--> 156 157 <!-- <xsl:value-of select="string-join($c1/ancestor::Term/@name except $c2/ancestor::Term/@name,'.')" /> --> 158 <!-- <xsl:copy-of select="$c1/ancestor::Term/@name except $c2/ancestor::Term/@name" />--> 159 <xsl:variable name="diff" select="$c1/ancestor::Term/xs:string(@name[not(.=$c2/ancestor::Term/xs:string(@name))])" /> 160 <!-- <xsl:message>diff: <xsl:value-of select="$diff" /></xsl:message> --> 161 <xsl:copy-of select="$diff" /> 162 163 </xsl:function> 164 165 <xsl:template match="*" mode="min-context" > 166 <xsl:copy> 167 <xsl:copy-of select="@*"></xsl:copy-of> 168 <xsl:apply-templates mode="min-context"> 169 </xsl:apply-templates> 170 </xsl:copy> 171 </xsl:template> 172 173 <!-- computing minimal unique path/index --> 174 <xsl:template match="Term" mode="min-context" > 175 <xsl:param name="all-terms" select="$cmd-terms-nested" /> 176 <xsl:param name="term" select="." /> 177 178 179 <!--<xsl:variable name="termset_id" select="if (exists(ancestor::Termset/@id)) then ancestor::Termset/@id else ancestor::Termset/@name" />--> 180 <xsl:variable name="termset_name" select="ancestor::Termset/@name" /> 181 182 <!-- unable to use lookup here - error: 183 net.sf.saxon.tree.wrapper.VirtualCopy "cannot be cast" to net.sf.saxon.om.DocumentInfo --> 184 <xsl:variable name="ambi_terms" select="$all-terms//Term[lower-case(@name)=lower-case($term/@name)]" /> 185 <!-- loookup did not work! 186 <xsl:variable name="ambi_terms" > 187 <xsl:call-template name="lookup"> 188 <xsl:with-param name="key" select="$term/@name"></xsl:with-param> 189 </xsl:call-template> 190 <xsl:for-each select="$all-terms-nested"> 191 <xsl:value-of select="key('term-name', lower-case($term/@name))"/> 192 </xsl:for-each> 193 </xsl:variable> --> 194 195 <xsl:variable name="min-path" > 196 <!-- don't apply prefix for the root element (=profile-name) --> 197 <xsl:if test="not($term/parent::Termset)" > 198 <xsl:value-of select="$termset_name" ></xsl:value-of><xsl:text>:</xsl:text> 199 </xsl:if> 200 201 <xsl:choose> 202 <xsl:when test="count($ambi_terms) > 1" > 203 <xsl:variable name="ambi_terms_parent" select="$ambi_terms/*[@name=$term/@name]" /> 204 <xsl:variable name="term1" select="." /> 205 <xsl:message>Term:<xsl:value-of select="$term1/@path" />|ambi: <xsl:value-of select="count($ambi_terms)" />|</xsl:message> 206 <xsl:variable name="minimal_contexts" > 207 <xsl:for-each select="$ambi_terms/*[not(@path=$term1/@path)]" > 208 <!-- [position() > current()/position()]" > --> 209 <item> 210 <xsl:variable name="diff" select="my:diffContext($term1,.)" /> 211 <!-- <xsl:message>diff: <xsl:value-of select="count($diff)" /></xsl:message>--> 212 <xsl:copy-of select="$diff" /> 213 214 </item> 215 </xsl:for-each> 216 </xsl:variable> 217 <!-- DEBUG: diffcontext1:<xsl:value-of select="count($minimal_contexts)" /> 218 |direct: <xsl:value-of select="count($minimal_contexts[1]/*)" />: <xsl:value-of select="$minimal_contexts[1]/*" />| 219 |item1: <xsl:value-of select="count($minimal_contexts/item[1]/*)" />: <xsl:value-of select="$minimal_contexts/item[1]/*" />| 220 cnt_mci:<xsl:value-of select="$minimal_contexts/*/count(tokenize(.,' '))" ></xsl:value-of>/ 221 max-strlen:<xsl:value-of select="max($minimal_contexts/*/string-length(.))" ></xsl:value-of> 222 --> 223 <xsl:variable name="last_contexts" select="distinct-values($minimal_contexts/*/tokenize(.,' ')[last()])" ></xsl:variable> 224 <!-- to get the order right --> 225 <xsl:for-each select="$last_contexts" > 226 <xsl:sort select="index-of(tokenize($term1/@context,'\.'),.)[1]" /> 227 <xsl:value-of select="." />.</xsl:for-each> 228 <!-- DEBUG: cnt_lc:<xsl:value-of select="count($last_contexts)" />} 229 cnt_tok:<xsl:value-of select="count(tokenize($term1/@context,'\.'))" /> 230 231 <xsl:for-each select="tokenize($term1/@context,'\.')" > 232 tokenizing-context:<xsl:value-of select="." />,<xsl:value-of select="current()" />| 233 <xsl:if test="$last_contexts[.=current()]" > 234 {<xsl:value-of select="." />} 235 236 </xsl:if> 237 </xsl:for-each> 238 --> 239 <!-- <xsl:value-of select="string-join(distinct-values($minimal_contexts/*/tokenize(.,' ')[last()]),'.')" ></xsl:value-of> --> 240 </xsl:when> 241 <xsl:otherwise> 242 </xsl:otherwise> 243 </xsl:choose> 244 <xsl:value-of select="@name" ></xsl:value-of> 245 </xsl:variable> 246 247 <xsl:copy> 248 <xsl:copy-of select="@*"></xsl:copy-of> 249 <!-- <xsl:copy-of select="$path" />--> 250 <xsl:attribute name="min-path" select="$min-path" /> 251 252 <xsl:apply-templates select="Term" mode="min-context" > 253 <xsl:with-param name="all-terms" select="$all-terms"></xsl:with-param> 254 </xsl:apply-templates> 255 256 </xsl:copy> 257 258 </xsl:template> 259 <!-- 260 <xsl:template name="lookup"> 261 <xsl:param name="key"/> 262 <xsl:for-each select="$all-terms-nested"> 263 <xsl:value-of select="key('term-name', $key)"/> 264 <xsl:message><xsl:value-of select="key('term-name', $key)"/></xsl:message> 265 </xsl:for-each> 266 <xsl:message></xsl:message> 267 </xsl:template> 268 269 --> 270 271 <xsl:function name="my:shortURL" > 272 <xsl:param name="url" /> 273 <!-- <xsl:value-of select="replace($url, 'http://www.isocat.org/datcat/','isocat:')" /> --> 274 <xsl:variable name="matching_termset" select="if($url!='') then $termsets_config/Termsets/*[url_prefix][not(url_prefix='')][starts-with($url,url_prefix)] else ()" /> 275 <!-- <xsl:variable name="matchinge_termset" select="if($url!='') then if ($terms_setup/Termsets/Termset[@url_prefix][starts-with($url,@url_prefix)]) then $terms_setup/Termsets/Termset[@url_prefix][starts-with($url,@url_prefix)][1] 276 else if $terms_setup/Termsets/Termset[@url][starts-with($url,@url)] then $terms_setup/Termsets/Termset[@url][starts-with($url,@url)][1] else ()" /> --> 277 <xsl:message>shortURL: <xsl:value-of select="$matching_termset/url_prefix" />:: <xsl:value-of select="$url" /> 278 </xsl:message> 279 <xsl:value-of select="if ($matching_termset/url_prefix and $matching_termset/url_prefix!='' and $url!='') then replace($url, $matching_termset[1]/url_prefix, concat(string-join($matching_termset/key,','),':')) else $url" /> 280 </xsl:function> 281 282 95 283 </xsl:stylesheet>
Note: See TracChangeset
for help on using the changeset viewer.