|
630 | 630 | </xsl:template> |
631 | 631 |
|
632 | 632 | <!-- Process decorations (color, border, rounded, width) on any element --> |
633 | | - <xsl:template match="*[@color or @border or @rounded or @width]" mode="get-output-class" priority="100"> |
| 633 | + <!-- Process spacing and shadow decorations on any element --> |
| 634 | + <xsl:template match="*[@margin or @padding or @shadow]" mode="get-output-class" priority="-1"> |
| 635 | + <xsl:variable |
| 636 | + name="margin" |
| 637 | + select="(@margin, (if (@shadow and @shadow != 'no' and @shadow != 'none' and not(contains(@outputclass, 'm-'))) then '3' else ()))[1]" |
| 638 | + /> |
| 639 | + <xsl:for-each select="tokenize(normalize-space($margin), '\s+')"> |
| 640 | + <xsl:choose> |
| 641 | + <xsl:when test="matches(., '^[tbsxy]([0-5]|auto)$')"> |
| 642 | + <xsl:value-of select="concat('m', substring(., 1, 1), '-', substring(., 2))"/> |
| 643 | + </xsl:when> |
| 644 | + <xsl:when test="matches(., '^e([0-5]|auto)$')"> |
| 645 | + <xsl:value-of select="concat('me-', substring(., 2))"/> |
| 646 | + </xsl:when> |
| 647 | + <xsl:when test="contains(., '-')"> |
| 648 | + <xsl:value-of select="."/> |
| 649 | + </xsl:when> |
| 650 | + <xsl:otherwise> |
| 651 | + <xsl:value-of select="concat('m-', .)"/> |
| 652 | + </xsl:otherwise> |
| 653 | + </xsl:choose> |
| 654 | + <xsl:text> </xsl:text> |
| 655 | + </xsl:for-each> |
| 656 | + <xsl:if |
| 657 | + test="@padding and not(contains(@class, ' topic/note ') or |
| 658 | + contains(@class, ' topic/pre ') or |
| 659 | + contains(@class, ' bootstrap-d/card ') or |
| 660 | + contains(@class, ' bootstrap-d/alert '))" |
| 661 | + > |
| 662 | + <xsl:for-each select="tokenize(normalize-space(@padding), '\s+')"> |
| 663 | + <xsl:choose> |
| 664 | + <xsl:when test="matches(., '^[tbsxy]([0-5]|auto)$')"> |
| 665 | + <xsl:value-of select="concat('p', substring(., 1, 1), '-', substring(., 2))"/> |
| 666 | + </xsl:when> |
| 667 | + <xsl:when test="matches(., '^e([0-5]|auto)$')"> |
| 668 | + <xsl:value-of select="concat('pe-', substring(., 2))"/> |
| 669 | + </xsl:when> |
| 670 | + <xsl:when test="contains(., '-')"> |
| 671 | + <xsl:value-of select="."/> |
| 672 | + </xsl:when> |
| 673 | + <xsl:otherwise> |
| 674 | + <xsl:value-of select="concat('p-', .)"/> |
| 675 | + </xsl:otherwise> |
| 676 | + </xsl:choose> |
| 677 | + <xsl:text> </xsl:text> |
| 678 | + </xsl:for-each> |
| 679 | + </xsl:if> |
| 680 | + <xsl:if test="@shadow"> |
| 681 | + <xsl:choose> |
| 682 | + <xsl:when test="@shadow='yes'"> |
| 683 | + <xsl:text>shadow </xsl:text> |
| 684 | + </xsl:when> |
| 685 | + <xsl:when test="@shadow='no' or @shadow='none'"> |
| 686 | + <xsl:text>shadow-none </xsl:text> |
| 687 | + </xsl:when> |
| 688 | + <xsl:otherwise> |
| 689 | + <xsl:text>shadow-</xsl:text> |
| 690 | + <xsl:value-of select="@shadow"/> |
| 691 | + <xsl:text> </xsl:text> |
| 692 | + </xsl:otherwise> |
| 693 | + </xsl:choose> |
| 694 | + </xsl:if> |
| 695 | + <xsl:next-match/> |
| 696 | + </xsl:template> |
| 697 | + |
| 698 | + <!-- Process decorations (color, border, rounded, width) on any element --> |
| 699 | + <xsl:template match="*[@color or @border or @rounded or @width]" mode="get-output-class" priority="-2"> |
634 | 700 | <xsl:if |
635 | 701 | test="@color and not(contains(@class, ' topic/note ') or |
636 | 702 | contains(@class, ' topic/pre ') or |
|
675 | 741 | </xsl:otherwise> |
676 | 742 | </xsl:choose> |
677 | 743 | </xsl:if> |
678 | | - <xsl:variable |
679 | | - name="margin" |
680 | | - select="(@margin, (if (@shadow and @shadow != 'no' and @shadow != 'none' and not(contains(@outputclass, 'm-'))) then '3' else ()))[1]" |
681 | | - /> |
682 | | - <xsl:if test="$margin"> |
683 | | - <xsl:text>m-</xsl:text> |
684 | | - <xsl:value-of select="$margin"/> |
685 | | - <xsl:text> </xsl:text> |
686 | | - </xsl:if> |
687 | | - <xsl:if |
688 | | - test="@padding and not(contains(@class, ' topic/note ') or |
689 | | - contains(@class, ' topic/pre ') or |
690 | | - contains(@class, ' bootstrap-d/card ') or |
691 | | - contains(@class, ' bootstrap-d/alert '))" |
692 | | - > |
693 | | - <xsl:text>p-</xsl:text> |
694 | | - <xsl:value-of select="@padding"/> |
695 | | - <xsl:text> </xsl:text> |
696 | | - </xsl:if> |
697 | | - <xsl:if test="@shadow"> |
698 | | - <xsl:choose> |
699 | | - <xsl:when test="@shadow='yes'"> |
700 | | - <xsl:text>shadow </xsl:text> |
701 | | - </xsl:when> |
702 | | - <xsl:when test="@shadow='no' or @shadow='none'"> |
703 | | - <xsl:text>shadow-none </xsl:text> |
704 | | - </xsl:when> |
705 | | - <xsl:otherwise> |
706 | | - <xsl:text>shadow-</xsl:text> |
707 | | - <xsl:value-of select="@shadow"/> |
708 | | - <xsl:text> </xsl:text> |
709 | | - </xsl:otherwise> |
710 | | - </xsl:choose> |
711 | | - </xsl:if> |
712 | 744 | <xsl:if test="@width"> |
713 | 745 | <xsl:text>w-</xsl:text> |
714 | 746 | <xsl:value-of select="@width"/> |
|
825 | 857 | </xsl:when> |
826 | 858 | </xsl:choose> |
827 | 859 | </xsl:template> |
| 860 | + |
| 861 | + <!-- |
| 862 | + The default set-output-class for a class of elements may be passed in with $default, |
| 863 | + but that default can be overridden with mode="get-output-class". |
| 864 | + In DITA Bootstrap we want these to be additive. |
| 865 | + --> |
| 866 | + <xsl:template match="*" mode="set-output-class" priority="10"> |
| 867 | + <xsl:param name="default"/> |
| 868 | + <xsl:variable name="output-class"> |
| 869 | + <xsl:apply-templates select="." mode="get-output-class"/> |
| 870 | + </xsl:variable> |
| 871 | + |
| 872 | + <xsl:variable name="using-output-class" as="xs:string*"> |
| 873 | + <xsl:value-of select="tokenize(normalize-space($output-class), '\s+')"/> |
| 874 | + <xsl:value-of select="tokenize(normalize-space($default), '\s+')"/> |
| 875 | + </xsl:variable> |
| 876 | + |
| 877 | + <xsl:variable name="ancestry" as="xs:string?"> |
| 878 | + <xsl:if test="$PRESERVE-DITA-CLASS = 'yes'"> |
| 879 | + <xsl:value-of> |
| 880 | + <xsl:apply-templates select="." mode="get-element-ancestry"/> |
| 881 | + </xsl:value-of> |
| 882 | + </xsl:if> |
| 883 | + </xsl:variable> |
| 884 | + <xsl:variable name="outputclass-attribute" as="xs:string"> |
| 885 | + <xsl:value-of> |
| 886 | + <xsl:apply-templates select="@outputclass" mode="get-value-for-class"/> |
| 887 | + </xsl:value-of> |
| 888 | + </xsl:variable> |
| 889 | + |
| 890 | + <xsl:variable |
| 891 | + name="classes" |
| 892 | + as="xs:string*" |
| 893 | + select="tokenize($ancestry, '\s+'), |
| 894 | + $using-output-class, |
| 895 | + tokenize($outputclass-attribute, '\s+')" |
| 896 | + /> |
| 897 | + <xsl:if test="exists($classes)"> |
| 898 | + <xsl:attribute name="class" select="distinct-values($classes)" separator=" "/> |
| 899 | + </xsl:if> |
| 900 | + </xsl:template> |
| 901 | + |
828 | 902 | </xsl:stylesheet> |
0 commit comments