486 |
486 |
487 |
487 |
488 <xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template> |
488 <xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template> |
489 |
489 |
490 |
490 |
491 <!-- path handling follows --> |
491 <xsl:include href="path-module.xsl"/> |
492 |
|
493 <xsl:template name="lastbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/> |
|
494 <xsl:if test="contains($string,$substr)"> |
|
495 <xsl:value-of select="substring-before($string,$substr)"/> |
|
496 <xsl:if test="contains(substring-after($string,$substr),$substr)"> |
|
497 <xsl:value-of select="$substr"/> |
|
498 </xsl:if> |
|
499 <xsl:call-template name="lastbefore"> |
|
500 <xsl:with-param name="string" select="substring-after($string,$substr)"/> |
|
501 <xsl:with-param name="substr" select="$substr"/> |
|
502 </xsl:call-template> |
|
503 </xsl:if> |
|
504 </xsl:template> |
|
505 |
|
506 <xsl:template name="joinpath"><xsl:param name="file"/><xsl:param name="rel"/> |
|
507 <xsl:choose> |
|
508 <xsl:when test="(contains($rel,'://') and not(contains(substring-before($rel,'://'),'/'))) or starts-with($rel,'/')"> <!-- absolute URI or absolute path--> |
|
509 <xsl:value-of select="$rel"/> |
|
510 </xsl:when> |
|
511 <xsl:otherwise> <!-- relative link --> |
|
512 <xsl:call-template name="reducepath"> |
|
513 <xsl:with-param name="file"> |
|
514 <xsl:call-template name="lastbefore"> |
|
515 <xsl:with-param name="string" select="$file"/> |
|
516 </xsl:call-template> |
|
517 <xsl:text>/</xsl:text> |
|
518 <xsl:value-of select="$rel"/> |
|
519 </xsl:with-param> |
|
520 </xsl:call-template> |
|
521 </xsl:otherwise> |
|
522 </xsl:choose> |
|
523 </xsl:template> |
|
524 |
|
525 <xsl:template name="reducepath"><xsl:param name="file"/> |
|
526 <xsl:call-template name="reducedotdotpath"> |
|
527 <xsl:with-param name="file"> |
|
528 <xsl:call-template name="reducedotpath"> |
|
529 <xsl:with-param name="file" select="$file"/> |
|
530 </xsl:call-template> |
|
531 </xsl:with-param> |
|
532 </xsl:call-template> |
|
533 </xsl:template> |
|
534 |
|
535 <xsl:template name="reducedotdotpath"><xsl:param name="file"/> |
|
536 <xsl:choose> |
|
537 <xsl:when test="starts-with($file,'../')"> |
|
538 <xsl:text>../</xsl:text> |
|
539 <xsl:call-template name="reducedotdotpath"> |
|
540 <xsl:with-param name="file" select="substring($file,4)"/> |
|
541 </xsl:call-template> |
|
542 </xsl:when> |
|
543 <xsl:when test="contains($file,'/../')"> |
|
544 <xsl:call-template name="reducepath"> |
|
545 <xsl:with-param name="file"> |
|
546 <xsl:call-template name="lastbefore"> |
|
547 <xsl:with-param name="string" select="substring-before($file,'/../')"/> |
|
548 </xsl:call-template> |
|
549 <xsl:text>/</xsl:text> |
|
550 <xsl:value-of select="substring-after($file,'/../')"/> |
|
551 </xsl:with-param> |
|
552 </xsl:call-template> |
|
553 </xsl:when> |
|
554 <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise> |
|
555 </xsl:choose> |
|
556 </xsl:template> |
|
557 |
|
558 <xsl:template name="reducedotpath"><xsl:param name="file"/> |
|
559 <xsl:choose> |
|
560 <xsl:when test="starts-with($file,'./')"> |
|
561 <xsl:call-template name="reducedotpath"> |
|
562 <xsl:with-param name="file" select="substring($file,3)"/> |
|
563 </xsl:call-template> |
|
564 </xsl:when> |
|
565 |
|
566 <xsl:when test="contains($file,'/./')"> |
|
567 <xsl:call-template name="reducepath"> |
|
568 <xsl:with-param name="file"> |
|
569 <xsl:value-of select="substring-before($file,'/./')"/> |
|
570 <xsl:text>/</xsl:text> |
|
571 <xsl:value-of select="substring-after($file,'/./')"/> |
|
572 </xsl:with-param> |
|
573 </xsl:call-template> |
|
574 </xsl:when> |
|
575 <xsl:when test="substring($file,string-length($file) - 1) = '/.'"> |
|
576 <xsl:value-of select="substring($file,1,string-length($file) - 2)"/> |
|
577 </xsl:when> |
|
578 <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise> |
|
579 </xsl:choose> |
|
580 </xsl:template> |
|
581 |
492 |
582 <!-- overridable templates follow --> |
493 <!-- overridable templates follow --> |
583 |
494 |
584 |
495 |
585 <xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show --> |
496 <xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show --> |