8 |
8 |
9 Initial Contributors: |
9 Initial Contributors: |
10 Nokia Corporation - initial contribution. |
10 Nokia Corporation - initial contribution. |
11 Contributors: |
11 Contributors: |
12 Description: |
12 Description: |
13 XSLT module for merging only two sysdef files according to the 3.0.0 rules. Old syntax not supported and must be converetd before calling. |
13 XSLT module for merging only two sysdef files according to the 3.0.1 rules. |
|
14 2.x and older syntax not supported and must be converetd before calling. |
|
15 |
|
16 Requires the including XSLT to also include path-module.xsl |
14 --> |
17 --> |
15 |
18 |
16 <xsl:variable name="defaultnamespace">http://www.symbian.org/system-definition</xsl:variable> |
19 <xsl:variable name="defaultnamespace">http://www.symbian.org/system-definition</xsl:variable> |
17 |
20 |
18 <xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models"> |
21 <xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models"> |
288 <xsl:if test="$base[1]/@id=$end/@id and not($base[@id=$to-sort[1]/@before])"> |
291 <xsl:if test="$base[1]/@id=$end/@id and not($base[@id=$to-sort[1]/@before])"> |
289 <!-- if at end, then this needs to be copied |
292 <!-- if at end, then this needs to be copied |
290 don't copy if the before ID is found in $base --> |
293 don't copy if the before ID is found in $base --> |
291 <xsl:apply-templates mode="merge-copy-of" select="$to-sort[1]"> |
294 <xsl:apply-templates mode="merge-copy-of" select="$to-sort[1]"> |
292 <xsl:with-param name="origin" select="$down"/> |
295 <xsl:with-param name="origin" select="$down"/> |
293 <xsl:with-param name="root" select="$end/ancestor::systemModel"/> |
296 <xsl:with-param name="root" select="$end/ancestor::SystemDefinition"/> |
294 </xsl:apply-templates> |
297 </xsl:apply-templates> |
295 </xsl:if> |
298 </xsl:if> |
296 <xsl:call-template name="copy-sorted-content"> |
299 <xsl:call-template name="copy-sorted-content"> |
297 <xsl:with-param name="base" select="$base"/> |
300 <xsl:with-param name="base" select="$base"/> |
298 <xsl:with-param name="to-sort" select="$to-sort[position() != 1]"/> |
301 <xsl:with-param name="to-sort" select="$to-sort[position() != 1]"/> |
379 </xsl:choose> |
382 </xsl:choose> |
380 </xsl:message> |
383 </xsl:message> |
381 <!-- if the removed item is in the downstream doc, just copy that and ignore the upstream contents --> |
384 <!-- if the removed item is in the downstream doc, just copy that and ignore the upstream contents --> |
382 <xsl:apply-templates mode="merge-copy-of" select="$match"> |
385 <xsl:apply-templates mode="merge-copy-of" select="$match"> |
383 <xsl:with-param name="origin" select="$down"/> |
386 <xsl:with-param name="origin" select="$down"/> |
384 <xsl:with-param name="root" select="$this/ancestor::systemModel"/> |
387 <xsl:with-param name="root" select="$this/ancestor::SystemDefinition"/> |
385 <xsl:with-param name="replaces" select="$replaces"/> |
388 <xsl:with-param name="replaces" select="$replaces"/> |
386 </xsl:apply-templates> |
389 </xsl:apply-templates> |
387 </xsl:when> |
390 </xsl:when> |
388 <xsl:otherwise> |
391 <xsl:otherwise> |
389 <!-- remove this if it's in the list of stuff to be replaced--> |
392 <!-- remove this if it's in the list of stuff to be replaced--> |
405 </xsl:when> |
408 </xsl:when> |
406 <xsl:when test="not($match/preceding-sibling::*[@id=$this/../*/@id]) and $other/*[@id= current()/@id]/preceding-sibling::*[@id and not(@before)]"> |
409 <xsl:when test="not($match/preceding-sibling::*[@id=$this/../*/@id]) and $other/*[@id= current()/@id]/preceding-sibling::*[@id and not(@before)]"> |
407 <!-- if this is the first item in other that's also in this, then put all new items from other here --> |
410 <!-- if this is the first item in other that's also in this, then put all new items from other here --> |
408 <xsl:apply-templates mode="merge-copy-of" select="$match/preceding-sibling::*[@id and not(@before)]"> |
411 <xsl:apply-templates mode="merge-copy-of" select="$match/preceding-sibling::*[@id and not(@before)]"> |
409 <xsl:with-param name="origin" select="$down"/> |
412 <xsl:with-param name="origin" select="$down"/> |
410 <xsl:with-param name="root" select="$this/ancestor::systemModel"/> |
413 <xsl:with-param name="root" select="$this/ancestor::SystemDefinition"/> |
411 <xsl:with-param name="replaces" select="$replaces"/> |
414 <xsl:with-param name="replaces" select="$replaces"/> |
412 </xsl:apply-templates> |
415 </xsl:apply-templates> |
413 </xsl:when> |
416 </xsl:when> |
414 </xsl:choose> |
417 </xsl:choose> |
415 |
418 |
416 <!-- just copy anything identified as being before this, assume they're all ok --> |
419 <!-- just copy anything identified as being before this, assume they're all ok --> |
417 <xsl:apply-templates mode="merge-copy-of" select="$other/*[@before=current()/@id]"> |
420 <xsl:apply-templates mode="merge-copy-of" select="$other/*[@before=current()/@id]"> |
418 <xsl:with-param name="remove-before" select="1"/> |
421 <xsl:with-param name="remove-before" select="1"/> |
419 <xsl:with-param name="origin" select="$down"/> |
422 <xsl:with-param name="origin" select="$down"/> |
420 <xsl:with-param name="root" select="$this/ancestor::systemModel"/> |
423 <xsl:with-param name="root" select="$this/ancestor::SystemDefinition"/> |
421 <xsl:with-param name="replaces" select="$replaces"/> |
424 <xsl:with-param name="replaces" select="$replaces"/> |
422 </xsl:apply-templates> |
425 </xsl:apply-templates> |
423 |
426 |
424 |
427 |
425 <xsl:copy> |
428 <xsl:copy> |
474 <!-- don't copy if explicitly or implicitly placed already--> |
477 <!-- don't copy if explicitly or implicitly placed already--> |
475 <xsl:for-each select="$match/*[not(@before) and not(following-sibling::*[@id=$this/*/@id])]"> |
478 <xsl:for-each select="$match/*[not(@before) and not(following-sibling::*[@id=$this/*/@id])]"> |
476 <xsl:if test="not($this/*[@id=current()/@id])"> |
479 <xsl:if test="not($this/*[@id=current()/@id])"> |
477 <xsl:apply-templates mode="merge-copy-of" select="."> |
480 <xsl:apply-templates mode="merge-copy-of" select="."> |
478 <xsl:with-param name="origin" select="$down"/> |
481 <xsl:with-param name="origin" select="$down"/> |
479 <xsl:with-param name="root" select="$this/ancestor::systemModel"/> |
482 <xsl:with-param name="root" select="$this/ancestor::SystemDefinition"/> |
480 <xsl:with-param name="replaces" select="$replaces"/> |
483 <xsl:with-param name="replaces" select="$replaces"/> |
481 </xsl:apply-templates> |
484 </xsl:apply-templates> |
482 </xsl:if> |
485 </xsl:if> |
483 </xsl:for-each> |
486 </xsl:for-each> |
484 </xsl:otherwise> |
487 </xsl:otherwise> |
490 |
493 |
491 <xsl:if test="self::layer and not(following-sibling::layer)"> |
494 <xsl:if test="self::layer and not(following-sibling::layer)"> |
492 <!-- for the last layer, tack on any remaining layers --> |
495 <!-- for the last layer, tack on any remaining layers --> |
493 <xsl:apply-templates mode="merge-copy-of" select="$other/layer[not(@before) and not(following-sibling::*[@id=$this/../layer/@id]) and not(@id=$this/../layer/@id)]"> |
496 <xsl:apply-templates mode="merge-copy-of" select="$other/layer[not(@before) and not(following-sibling::*[@id=$this/../layer/@id]) and not(@id=$this/../layer/@id)]"> |
494 <xsl:with-param name="origin" select="$down"/> |
497 <xsl:with-param name="origin" select="$down"/> |
495 <xsl:with-param name="root" select="$this/ancestor::systemModel"/> |
498 <xsl:with-param name="root" select="$this/ancestor::SystemDefinition"/> |
496 <xsl:with-param name="replaces" select="$replaces"/> |
499 <xsl:with-param name="replaces" select="$replaces"/> |
497 </xsl:apply-templates> |
500 </xsl:apply-templates> |
498 </xsl:if> |
501 </xsl:if> |
499 </xsl:template> |
502 </xsl:template> |
500 |
503 |
503 <xsl:template match="*" mode="merge-copy-of"> |
506 <xsl:template match="*" mode="merge-copy-of"> |
504 <xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed --> |
507 <xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed --> |
505 <xsl:param name="origin"/> <!--the element containing the @name to use the origin-model attribute --> |
508 <xsl:param name="origin"/> <!--the element containing the @name to use the origin-model attribute --> |
506 <xsl:param name="root"/> <!--the systemModel element in the upstream doc --> |
509 <xsl:param name="root"/> <!--the systemModel element in the upstream doc --> |
507 <xsl:param name="replaces" select="ancestor::SystemDefinition/descendant::*[(self::component or self::collection or self::package or self::layer) and not(ancestor::meta)]/@replace"/> <!-- recalculate this is necessarfy, but should just pass down as a param --> |
510 <xsl:param name="replaces" select="ancestor::SystemDefinition/descendant::*[(self::component or self::collection or self::package or self::layer) and not(ancestor::meta)]/@replace"/> <!-- recalculate this is necessarfy, but should just pass down as a param --> |
508 |
|
509 <xsl:variable name="moved" select="$root/descendant::*[name()=name(current()/..) and @id!=current()/../@id]/*[@id=current()/@id]"/> |
511 <xsl:variable name="moved" select="$root/descendant::*[name()=name(current()/..) and @id!=current()/../@id]/*[@id=current()/@id]"/> |
510 <xsl:choose> |
512 <xsl:choose> |
511 <!-- this might slow things down, consider making optional --> |
513 <!-- this might slow things down, consider making optional --> |
512 <xsl:when test="not(self::layer) and (count($moved) and not($moved[ancestor-or-self::*/@id=$replaces]) )"> |
514 <xsl:when test="not(self::layer) and (count($moved) and not($moved[ancestor-or-self::*/@id=$replaces]) )"> |
513 <xsl:message>Warning: <xsl:value-of select="name()"/> "<xsl:value-of select="@id"/>" moved in downstream model. Ignoring moved <xsl:value-of select="name()"/> |
515 <xsl:message>Warning: <xsl:value-of select="name()"/> "<xsl:value-of select="@id"/>" moved in downstream model. Ignoring moved <xsl:value-of select="name()"/> |
541 </xsl:otherwise> |
543 </xsl:otherwise> |
542 </xsl:choose> |
544 </xsl:choose> |
543 </xsl:otherwise> |
545 </xsl:otherwise> |
544 </xsl:choose> |
546 </xsl:choose> |
545 </xsl:template> |
547 </xsl:template> |
546 |
|
547 |
|
548 <xsl:template match="comment()|@*" mode="merge-copy-of"> |
548 <xsl:template match="comment()|@*" mode="merge-copy-of"> |
549 <xsl:copy-of select="."/> |
549 <xsl:copy-of select="."/> |
550 </xsl:template> |
550 </xsl:template> |
551 |
551 |
552 |
552 |
553 <xsl:template name="merge-copy-of-atts"> |
553 <xsl:template name="merge-copy-of-atts"> |
554 <xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed --> |
554 <xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed --> |
555 <xsl:param name="root"/> <!--the systemModel element in the upstream doc --> |
555 <xsl:param name="root"/> <!--the systemModel element in the upstream doc --> |
|
556 |
556 <xsl:choose> |
557 <xsl:choose> |
557 <xsl:when test="$remove-before"> |
558 <xsl:when test="$remove-before"> |
558 <xsl:copy-of select="@*[name()!='before' and name()!='replace']"/> |
559 <xsl:copy-of select="@*[name()!='before' and name()!='replace']"/> |
559 </xsl:when> |
560 </xsl:when> |
560 <xsl:otherwise><xsl:copy-of select="@*[name()!='replace']"/></xsl:otherwise> |
561 <xsl:otherwise><xsl:copy-of select="@*[name()!='replace']"/></xsl:otherwise> |
611 </xsl:copy> |
612 </xsl:copy> |
612 </xsl:template> |
613 </xsl:template> |
613 |
614 |
614 |
615 |
615 |
616 |
616 <xsl:template match="unit/@bldFile | unit/@mrp | unit/@bldfile" mode="merge-copy-of"> |
617 |
|
618 <xsl:template match="meta" mode="merge-copy-of"> |
|
619 <xsl:param name="origin"/> <!--the element containing the @name to use the origin-model attribute --> |
|
620 <xsl:param name="root"/> <!--the systemModel element in the upstream doc --> |
|
621 <xsl:copy> |
|
622 <xsl:apply-templates select="@*" mode="merge-copy-of"> |
|
623 <xsl:with-param name="origin" select="$origin"/> |
|
624 <xsl:with-param name="root" select="$root"/> |
|
625 </xsl:apply-templates> |
|
626 <xsl:copy-of select="node()"/> |
|
627 </xsl:copy> |
|
628 </xsl:template> |
|
629 |
|
630 |
|
631 <xsl:template match="unit/@bldFile | unit/@mrp | unit/@base | meta/@href" mode="merge-copy-of"> |
617 <xsl:param name="origin" select="/.."/> <!--the element containing the @name to use the origin-model attribute --> |
632 <xsl:param name="origin" select="/.."/> <!--the element containing the @name to use the origin-model attribute --> |
618 |
633 |
619 <xsl:attribute name="{name()}"> |
634 <xsl:attribute name="{name()}"> |
620 <xsl:choose> |
635 <xsl:choose> |
621 <xsl:when test="not($origin/@pathto)"><xsl:value-of select="."/></xsl:when> |
636 <xsl:when test="not($origin/@pathto)"><xsl:value-of select="."/></xsl:when> |
625 <xsl:when test="contains($origin/@pathto,'://') and not(contains(substring-before($origin/@pathto,'://'),'/'))"> <!-- absolute URI for downstream sysdef not valif for unit paths, just copy and raise warning--> |
640 <xsl:when test="contains($origin/@pathto,'://') and not(contains(substring-before($origin/@pathto,'://'),'/'))"> <!-- absolute URI for downstream sysdef not valif for unit paths, just copy and raise warning--> |
626 <xsl:message>ERROR: Could not resolve relative path in downstream file: <xsl:value-of select="."/> relative to absolute URI <xsl:value-of select="$origin/@pathto"/></xsl:message> |
641 <xsl:message>ERROR: Could not resolve relative path in downstream file: <xsl:value-of select="."/> relative to absolute URI <xsl:value-of select="$origin/@pathto"/></xsl:message> |
627 <xsl:value-of select="."/> |
642 <xsl:value-of select="."/> |
628 </xsl:when> |
643 </xsl:when> |
629 <xsl:otherwise> <!-- relative link --> |
644 <xsl:otherwise> <!-- relative link --> |
630 <xsl:call-template name="lastbefore"> |
645 <xsl:call-template name="joinpath"> |
631 <xsl:with-param name="string" select="$origin/@pathto"/> |
646 <xsl:with-param name="file" select="$origin/@pathto"/> |
632 </xsl:call-template>/<xsl:value-of select="."/> |
647 <xsl:with-param name="rel" select="."/> |
|
648 </xsl:call-template> |
633 </xsl:otherwise> |
649 </xsl:otherwise> |
634 </xsl:choose> |
650 </xsl:choose> |
635 </xsl:attribute> |
651 </xsl:attribute> |
636 </xsl:template> |
652 </xsl:template> |
637 |
|
638 |
|
639 <!-- path handling follows --> |
|
640 |
|
641 <xsl:template name="lastbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/> |
|
642 <xsl:if test="contains($string,$substr)"> |
|
643 <xsl:value-of select="substring-before($string,$substr)"/> |
|
644 <xsl:if test="contains(substring-after($string,$substr),$substr)"> |
|
645 <xsl:value-of select="$substr"/> |
|
646 </xsl:if> |
|
647 <xsl:call-template name="lastbefore"> |
|
648 <xsl:with-param name="string" select="substring-after($string,$substr)"/> |
|
649 <xsl:with-param name="substr" select="$substr"/> |
|
650 </xsl:call-template> |
|
651 </xsl:if> |
|
652 </xsl:template> |
|
653 |
|
654 </xsl:stylesheet> |
653 </xsl:stylesheet> |