Changeset 2552
- Timestamp:
- 02/07/13 15:45:59 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
metadata/branches/clarin2imdi-resourcerefs/toolkit/xslt/imdi2clarin.xsl
r2551 r2552 230 230 </xsl:template> 231 231 232 <!-- Used to create resource refs on actors, sources and languages -->233 <xsl:template name="CreateResourceRefAttribute">232 <!-- Used to create the ResourceRef (single ref) attribute on actors and languages --> 233 <xsl:template match="@ResourceRef" mode="CreateResourceRefAttribute"> 234 234 <xsl:choose> 235 <!-- Only add attribute if a resource with the referenced id exists --> 235 236 <xsl:when test="$keep-resource-refs 236 and string-length(@ResourceRef) > 0 237 and (boolean(//MediaFile/@ResourceId = @ResourceRef) 238 or boolean(//WrittenResource/@ResourceId = @ResourceRef))"> 239 <xsl:attribute name="ref" select="@ResourceRef"/> 237 and string-length(.) > 0 238 and (boolean(//MediaFile/@ResourceId = .) 239 or boolean(//WrittenResource/@ResourceId = .)) 240 "> 241 <xsl:attribute name="ref" select="."/> 240 242 </xsl:when> 243 </xsl:choose> 244 </xsl:template> 245 246 <!-- Used to create the ResourceRefs attribute (multiple refs) on sources --> 247 <xsl:template match="@ResourceRefs" mode="CreateResourceRefAttribute"> 248 <xsl:variable name="resourceRefsValid"> 249 <xsl:call-template name="CheckResourceRefsValidity"> 250 <xsl:with-param name="resourceRefs" select="concat(normalize-space(string(.)),' ')"></xsl:with-param> 251 </xsl:call-template> 252 </xsl:variable> 253 <xsl:if test="$resourceRefsValid = 'true'"> 254 <xsl:attribute name="ref" select="."/> 255 </xsl:if> 256 </xsl:template> 257 258 <!-- Recursive function that checks whether all references in a ResourceRefs attribute are actually valid --> 259 <xsl:template name="CheckResourceRefsValidity" > 260 <xsl:param name="resourceRefs"/> 261 <xsl:choose> 262 <!-- empty resourceRefs attribute is always valid --> 263 <xsl:when test="string-length($resourceRefs) = 0">true</xsl:when> 264 <xsl:otherwise> 265 <!-- check first ref (CAR) --> 266 <xsl:variable name="firstRef" select="substring-before($resourceRefs,' ')"/> 267 <xsl:choose> 268 <xsl:when test="boolean(//MediaFile/@ResourceId = $firstRef) or boolean(//WrittenResource/@ResourceId = $firstRef)"> 269 <!-- a resource with the same ref exists --> 270 <xsl:call-template name="CheckResourceRefsValidity" > 271 <!-- check remainder (CDR) --> 272 <xsl:with-param name="resourceRefs" select="substring-after($resourceRefs,' ')" /> 273 </xsl:call-template> 274 </xsl:when> 275 <!-- if this one does not match, discard entire resourceRefs --> 276 <xsl:otherwise>false</xsl:otherwise> 277 </xsl:choose> 278 </xsl:otherwise> 241 279 </xsl:choose> 242 280 </xsl:template> … … 471 509 <xsl:for-each select="Language"> 472 510 <Content_Language> 473 <xsl: call-template name="CreateResourceRefAttribute"/>511 <xsl:apply-templates mode="CreateResourceRefAttribute" select="@ResourceRef"/> 474 512 <Id> 475 513 <xsl:value-of select=" ./Id"/> … … 522 560 <xsl:for-each select="Actor"> 523 561 <Actor> 524 <xsl: call-template name="CreateResourceRefAttribute"/>562 <xsl:apply-templates mode="CreateResourceRefAttribute" select="@ResourceRef"/> 525 563 <Role> 526 564 <xsl:value-of select=" ./Role"/> … … 588 626 <xsl:for-each select="Language"> 589 627 <Actor_Language> 590 <xsl: call-template name="CreateResourceRefAttribute" />628 <xsl:apply-templates mode="CreateResourceRefAttribute" select="@ResourceRef" /> 591 629 <Id> 592 630 <xsl:value-of select=" ./Id"/> … … 813 851 <xsl:template match="Source"> 814 852 <Source> 815 <xsl: call-template name="CreateResourceRefAttribute"/>853 <xsl:apply-templates mode="CreateResourceRefAttribute" select="@ResourceRefs"/> 816 854 <Id> 817 855 <xsl:value-of select=" ./Id"/>
Note: See TracChangeset
for help on using the changeset viewer.