# FTE mode for editing XSLT files
# created by Philippe Kirsanov
# philippe@mail333.com
# http://members.shaw.ca/phwp71/IT/
# Revision October 03, 2003

# XML+XSLT declaration
sub XSLT_Base {
    MoveFileStart; MoveLineStart;
    InsertString "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; LineNew;
    InsertString "<xsl:transform version=\"1.0\" xmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\"";
    LineNew;
    4:MoveRight; InsertString "xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\"";
    LineNew;
    InsertString "exclude-result-prefixes=\"msxsl\">";
    LineNew;
    InsertString "<xsl:output method=\"html\" version=\"4.0\" encoding=\"UTF-8\" indent=\"yes\"";
    LineNew;
    InsertString "doctype-public=\"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \/>";
    LineNew;
    InsertString "<xsl:preserve-space elements=\"*\" \/>";
    2:LineNew;
    4:MoveLeft;
    LineNew;
    InsertString "</xsl:transform>"; LineNew;
    2:MoveUp; MoveLineStart;
}

sub XSLT_Template {
    InsertString "<xsl:template match=\"\" mode=\"\" name=\"\">"; LineNew;
    InsertString "<\/xsl:template>"; LineNew;
    2:MoveUp; MoveLineEnd; 10:MoveLeft;
}

sub XSLT_Param {
    InsertString "<xsl:param name=\"\" />"; LineNew;
    1:MoveUp; MoveLineEnd; 4:MoveLeft;
}

sub XSLT_Variable {
    InsertString "<xsl:variable name=\"\" select=\"\" />"; LineNew;
    1:MoveUp; MoveLineEnd; 14:MoveLeft;
}

sub XSLT_ApplyTemplate {
    InsertString "<xsl:apply-templates select=\"\" mode=\"\">"; LineNew;
    4:MoveRight; InsertString "<xsl:sort select=\"\" data-type=\"\" />"; LineNew;
    InsertString "<xsl:with-param name=\"\" select=\"\" />"; LineNew;
    4:MoveLeft; InsertString "</xsl:apply-templates>"; LineNew;
    4:MoveUp; MoveLineEnd; 10:MoveLeft;
}

sub XSLT_CallTemaplate {
    InsertString "<xsl:call-template name=\"\">"; LineNew;
    4:MoveRight; InsertString "<xsl:with-param name=\"\" select=\"\" />"; LineNew;
    4:MoveLeft; InsertString "</xsl:call-template>"; LineNew;
    3:MoveUp; MoveLineEnd; 2:MoveLeft;
}

sub XSLT_If {
    InsertString "<xsl:if test=\"\">"; LineNew;
    InsertString "</xsl:if>"; LineNew;
    2:MoveUp; MoveLineEnd; 2:MoveLeft;
}

sub XSLT_CopyOf {
    InsertString "<xsl:copy-of select=\"\" />"; LineNew;
    1:MoveUp; MoveLineEnd; 4:MoveLeft;
}

sub XSLT_Copy {
    InsertString "<xsl:copy use-attribute-sets=\"\">"; LineNew;
    InsertString "</xsl:copy>"; LineNew;
    2:MoveUp; MoveLineEnd; 2:MoveLeft;
}

sub XSLT_ValueOf {
    InsertString "<xsl:value-of select=\"\" disable-output-escaping=\"no\" />"; LineNew;
    1:MoveUp; MoveLineEnd; 33:MoveLeft;
}

sub XSLT_Text {
    InsertString "<xsl:text disable-output-escaping=\"no\">";
    InsertString "</xsl:text>"; LineNew;
    1:MoveUp; MoveLineEnd; 11:MoveLeft;
}

sub XSLT_ForEach {
    InsertString "<xsl:for-each select=\"\">"; LineNew;
    InsertString "</xsl:for-each />"; LineNew;
    2:MoveUp; MoveLineEnd; 2:MoveLeft;
}

sub XSLT_Choose {
    InsertString "<xsl:choose>"; LineNew;
    4:MoveRight; InsertString "<xsl:when test=\"\">"; LineNew;
    InsertString "</xsl:when>"; LineNew;
    InsertString "<xsl:otherwise>"; LineNew;
    InsertString "</xsl:otherwise>"; LineNew;
    4:MoveLeft; InsertString "</xsl:choose>"; LineNew;
    5:MoveUp; MoveLineEnd; 2:MoveLeft;
}

sub XSLT_Key {
    InsertString "<xsl:key name=\"\" match=\"\" use=\"\" />"; LineNew;
    1:MoveUp; MoveLineStart; 15:MoveRight;
}

sub XSLT_Sort {
    InsertString "<xsl:sort select=\"\" lang=\"\" data-type=\"\" order=\"\" case-order=\"\" />";
    LineNew;
1:MoveUp; MoveLineStart; 18:MoveRight;
}



colorize XSLT {
    SyntaxParser = 'SIMPLE';
    
    color {
        { 'Normal',     'Editor_Default' },
        { 'Command',    'Markup_Punctuation' },
        { 'String',     'Markup_String' },
        { 'Symbol',     'Markup_Control' },
        { 'Tag',        'Markup_Tag' },
        { 'Comment',    'Markup_Comment' },
	{ 'Directive',  'Markup_Symbol' },
	{ 'Special',    'Markup_Special' },
	{ 'Variable',   'Lang_Variable' },
	{ 'Keyword',    'Editor_Keywords' },
    };
    
    keyword "Editor_Keywords" { # HTML 4.0 keywords
        "a", "abbr", "acronym", "address", "area", "b", "base", "bdo",
        "big", "blockquote", "body", "br", "button", "caption", "cite",
        "code", "col", "colgroup", "dd", "del", "dfn", "div", "dl",
        "dt", "em", "fieldset", "form", "frame", "frameset", "h1", "h2",
        "h3", "h4", "h5", "h6", "head", "hr", "html", "i", "iframe",
        "img", "input", "ins", "kbd", "label", "legend", "li", "map",
        "meta", "noframes", "noscript", "object", "ol", "optgroup",
        "option", "p", "param", "pre", "q", "samp", "script", "select",
        "small", "span", "strong", "style", "sub", "sup", "table",
        "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr",
        "tt", "ul", "var"
    };

    keyword "Editor_Keywords2" { # Secondary keywords
        "above", "absbottom", "action", "align", "alink", "all", "alt",
        "auto", "background", "baseline", "below", "bgcolor", "border",
        "bordercolor", "bottom", "box", "button", "cellpadding",
        "cellspacing", "center", "checkbox", "checked", "circle", "class",
        "clear", "codebase", "color", "cols", "colspan", "compact",
        "coords", "datetime", "default", "dir", "disc", "enctype",
        "face", "file", "for", "frame", "frameborder", "get", "groups",
        "height", "hidden", "href", "hsides", "hspace", "image", "ismap",
        "justify", "label", "language", "left", "lhs", "link", "ltr",
        "mailto", "marginheight", "marginwidth", "maxlength", "method",
        "middle", "multiple", "name", "no", "nohref", "none", "noresize",
        "noshade", "nowrap", "onclick", "onmouseout", "onmouseover",
        "param", "password", "poly", "post", "prompt", "public", "radio",
        "rect", "rel", "reset", "rev", "rhs", "right", "rows", "rowspan",
        "rtl", "rules", "scrolling", "selected", "shape", "size",
        "square", "src", "start", "subject", "submit", "target", "text",
        "top", "type", "usemap", "valign", "value", "vlink", "void",
        "vsides", "vspace", "width", "yes", "_blank", "_parent", "_self",
        "_top", "id"
    };
    
    keyword "Editor_Keywords5" { # Deprecated in HTML 4.01
        "basefont", "font", "s", "strike", "u", "applet", "dir",
        "isindex", "menu"
    };
    
    h_state 0 { 'Normal' }
    h_trans { 10, '<', '<xsl:', 'Directive' }   # Open XSLT Tag
    h_trans { 10, '<', '</xsl:', 'Directive' }  # Close XSLT Tag
    h_trans { 7, '<', '<?', 'Special' }         # Processing Instruction
    h_trans { 5, '<', '<!--', 'Comment' }       # Comment
    h_trans { 18, '<', '<![CDATA[', 'Keyword' } # CDATA
    h_trans { 1, '<', '<', 'Command' }          # Open Non-XSLT Tag
    h_trans { 2, '<', '&', 'Symbol' }           # Close Non-XSLT Tag
    
    # Not-XSLT tag
    h_state 1 { 'Command' }
    h_trans { 0, '>', '>', 'Command' }          # End
    h_trans { 3, '<', '\'', 'String' }          # String
    h_trans { 4, '<', '"', 'String' }           # String
    h_trans { 7, '<', '?>', 'Special' }         # Begin
    h_wtype { -1, -1, -1, 'i', 'a-zA-Z0-9_\-' } # Tag Text
    
    # Entity
    h_state 2 { 'Symbol' }
    h_trans { 0, '>', ';', 'Symbol' }           # End
    h_trans { 0, '-S', '#a-zA-Z0-9', 'Symbol' } # Entity Text
    
    # String
    h_state 3 { 'String' }
    h_trans { 8, '<', '&', 'Symbol' }           # Entity
    h_trans { 1, '>', '\'', 'String' }          # End
    
    # String
    h_state 4 { 'String' }
    h_trans { 9, '<', '&', 'Symbol' }           # Entity
    h_trans { 1, '>', '"', 'String' }           # End
    
    # Format Comment End Symbols
    h_state 5 { 'Comment' }
    h_trans { 6, '>', '--', 'Comment' }         # End (Symbols)
    
    h_state 6 { 'Special' }
    h_trans { 5, '>', '--', 'Comment' }         # Format Comment End Symbols
    h_trans { 0, '>', '>', 'Comment' }          # End
    
    # Processing Instructions
    h_state 7 { 'Special' }
    h_trans { 1, '-S', '<?', 'Special' }        # Begin
    h_trans { 0, '-S', '?>', 'Special' }        # End
    
    # Entity
    h_state 8 { 'Symbol' }
    h_trans { 3, '>', ';', 'Symbol' }           # End
    h_trans { 3, '-S', '#a-zA-Z0-9', 'Symbol' } # Entity Text
    
    # Entity
    h_state 9 { 'Symbol' }
    h_trans { 4, '>', ';', 'Symbol' }           # End
    h_trans { 4, '-S', '#a-zA-Z0-9', 'Symbol' } # Entity Text
    
    
    # XSLT tags
    h_state 10 { 'Special' }
    h_wtype { -1, 15, 15, '', 'a-z\-' }         # Tags
    h_words 'Markup_Symbol' {
	'apply-imports', 'apply-templates', 'attribute', 'attribute-set', 'call-template',
	'choose', 'comment', 'copy', 'copy-of', 'decimal-format', 'element', 'fallback',
	'for-each', 'if', 'import', 'include', 'key', 'message', 'namespace-alias',
	'number', 'otherwise', 'output', 'param', 'preserve-space', 'processing-instruction',
	'sort', 'strip-space', 'stylesheet', 'template', 'text', 'transform', 'value-of',
	'variable', 'when', 'with-param'
    }
    
    # String inside XSLT tag
    h_state 11 { 'String' }
    h_trans { 13, '<', '&', 'Symbol' }          # Entity
    h_trans { 16, '<', '$', 'Variable' }        # Variable
    h_trans { 11, 's', ':.*|@[]()', 'Tag' }     # Special Symbols
    h_trans { 15, '>', '\'', 'String' }         # End of String
    
    # String inside XSLT tag
    h_state 12 { 'String' }
    h_trans { 14, '<', '&', 'Symbol' }          # Entity
    h_trans { 17, '<', '$', 'Variable' }        # Variable
    h_trans { 12, 's', ':.*|@[]()', 'Tag' }     # Special Symbols
    h_trans { 15, '>', '"', 'String' }          # End of String
    
    # Entity
    h_state 13 { 'Symbol' }
    h_trans { 11, '>', ';', 'Symbol' }          # End of Entity
    h_trans { 11, '-S', '#a-zA-Z0-9', 'Symbol' }# Entity Text
    
    # Entity
    h_state 14 { 'Symbol' }
    h_trans { 12, '>', ';', 'Symbol' }          # End of Entity
    h_trans { 12, '-S', '#a-zA-Z0-9', 'Symbol' }# Entity Text
    
    # Process XSLT tag
    h_state 15 { 'Command' }
    h_trans { 0, '>', '>', 'Directive' }        # End of Tag
    h_trans { 11, '<', '\'', 'String' }         # String
    h_trans { 12, '<', '"', 'String' }          # String
    h_trans { 19, '<', 'xmlns:', 'Keyword' }    # Namespace
    h_wtype { -1, -1, -1, '', 'a-z\-' }         # Tags
#    h_words 'Markup_Control' {
    # XSLT attributes
    h_words 'Markup_Symbol' {
	'test', 'select', 'mode', 'name', 'namespace', 'use-attribute-sets', 'decimal-separator',
	'grouping-separator', 'infinity', 'minus-sign', 'NaN', 'percent', 'per-mille',
	'zero-digit', 'digit', 'pattern-separator', 'href', 'match', 'use', 'terminate',
	'stylesheet-prefix', 'result-prefix', 'level', 'count', 'from', 'value', 'format',
	'lang', 'letter-value', 'grouping-size', 'method', 'version', 'encoding',
	'omit-xml-declaration', 'standalone', 'doctype-public', 'doctype-system',
	'cdata-section-elements', 'indent', 'media-type', 'elements', 'data-type', 'order',
	'case-order', 'id', 'extension-element-prefixes', 'exclude-result-prefixes',
        'priority', 'disable-output-escaping'
    }
    
    # Variable
    h_state 16 { 'Variable' }
    h_trans { 11, '-S', 'a-zA-Z0-9_\$', 'Variable' }
    
    # Variable
    h_state 17 { 'Variable' }
    h_trans { 12, '-S', 'a-zA-Z0-9_\$', 'Variable' }
    
    # CDATA
    h_state 18 { 'String' }
    h_trans { 0, '<', ']]>', 'Keyword' }
    
    # >>> Namespace
    h_state 19 { 'Special' }
    h_trans { 15, '>', '=', 'Command' }          # End of Namespace
    h_trans { 20, '-s', 'a-z\_', 'Tag' }
    # First qname is azure
    h_state 20 { 'Tag' }
    h_wtype { -1, 21, 21, '', 'a-z0-9\-\_' }
    # Second qname must be red
    h_state 21 { 'Special' }
    h_trans { 15, '>', '=', 'Command' }
    # <<< Namespace

}

mode XSLT: HTML {
    FileNameRx          = /\.\c{{XSLT?}|{XML}|{XDR}|{WSC}}$/;
    TabSize             = 4;
    SpaceTabs           = 0;
    ShowTabs            = 1;
    HilitOn             = 1;
    Colorizer           = "XSLT";
    MultiLineHilit      = 1;
    AutoHilitParen      = 1;

    RoutineRegexp       = /\<xsl\:template/;

    SaveFolds           = 2;      # save fold info at end of line
    CommentStart        = " <!--";
    CommentEnd          = "-->";
}


eventmap XSLT {
    key [C+E_8]     { XSLT_Base }
    
    key [C+E_e]     { XSLT_Template }
    key [C+E_p]     { XSLT_Param }
    key [C+E_r]     { XSLT_Variable }
    key [C+E_a]     { XSLT_ApplyTemplate }
    key [C+E_l]     { XSLT_CallTemaplate }
    key [C+E_c]     { XSLT_CopyOf }
    key [C+E_o]     { XSLT_Copy }
    key [C+E_h]     { XSLT_Choose }
    key [C+E_i]     { XSLT_If }
    key [C+E_v]     { XSLT_ValueOf }
    key [C+E_t]     { XSLT_Text }
    key [C+E_f]     { XSLT_ForEach }
    key [C+E_k]     { XSLT_Key }
    key [C+E_s]     { XSLT_Sort }
}
