1

I want .xslt files to be highlighted as XML in jEdit.

How to do it in jEdit?

porton
  • 5,214
  • 11
  • 47
  • 95
  • Hmm, mine does it when extension is .xslt but uses xsl mode when extension is .xsl - what does your jedit use for highlighting when you open .xslt? For a single buffer, goto Utilities Menu -> Buffer Options and select xml from the Edit Mode dropdown - but I suppose you want a permanent solution – Stefan Hegny Jun 02 '16 at 20:09
  • @StefanHegny Your `xslt` file starts with a proper XML primer which makes jEdit open it as `xml` file. You might want to reconfigure your jEdit though, as there is a dedicated `xsl` mode, but that is only configured to the standard extension `xsl`, as `xslt` is not quite correct as file extension. :-) – Vampire Jun 06 '16 at 12:18
  • Thx @Vampire, I've been using xslt a lot and most have extension .xsl and no xml primer, so I'm mostly using (and appreciating) the xslt mode. I've no idea why OP would want soth different.... – Stefan Hegny Jun 06 '16 at 12:33

2 Answers2

2

There are different possible solutions according to what you want.
Besides that, there is an xsl mode that you might prefer for .xslt files over the xml mode. That mode is also the default for .xsl files which is the standard extension for XSL(T) scripts.
But as you asked for xml, I'll keep with that in the following descriptions.

  • If your .xslt file starts with an XML header like <?xml version="1.0" ?> (actually the important part is the <?xml in the beginning), your file is automatically highlighted with the xml mode, independent of its name

  • If you want to highlight the currently viewed file with a specific mode as long as it stays in the recent files list, just change the mode in the buffer settings, reachable through double click in the status bar on (<mode>,<wrap>,<encoding>) or via Utilities -> Buffer Settings...

  • If you want to highlight a file always with a specific mode, no matter in which jEdit you open it, embed the mode as buffer-local property in the first or last 10 lines of the file like <!-- :mode=xml: -->

  • If you want to highlight all files that end with .xslt with the xml mode, you need to edit your mode settings. For this

    • go to Utilities -> Global Options... -> jEdit -> Editing
    • select the xml mode
    • uncheck Use default settings
    • edit the File name glob to also match .xslt files
Vampire
  • 35,631
  • 4
  • 76
  • 102
1

Permanent solution (assuming linux, you didn't specify a system)

Terminate jedit.

Copy the file /usr/share/jedit/modes/xml.xml to your local jedit pref directory under modes/

cp /usr/share/jedit/modes/xml.xml ~/.jedit/modes

Edit ~/.jedit/modes/catalog so that it looks

<?xml version="1.0"?>
<!DOCTYPE MODES SYSTEM "catalog.dtd">

<MODES>

<MODE NAME="xml"                FILE="xml.xml"
                                FILE_NAME_GLOB="*.{xml,xhtml,xslt}" />
<!-- Add lines like the following, one for each edit mode you add: -->
<!-- <MODE NAME="foo" FILE="foo.xml" FILE_NAME_GLOB="*.foo" /> -->

</MODES>

or to taste, look at the xml/xsl entries in /usr/share/jedit/modes/catalog

If you are the master of your machine, you can also edit /usr/share/jedit/modes/catalog directly and modify the FILE_NAME_GLOB="*.{xml,xslt,xhtml,xsd,qrc,ui,docbook}" in the MODE NAME="xml" part

Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26
  • 1
    This is a 'little' overkill. You can simply use the settings dialog. No need for any file manipulations here. – Vampire Jun 03 '16 at 10:08
  • @Vampire, sure it is i a hack, I probably would have used before going to SO myself, but I see that I get good answers here even for questions not put myself... – Stefan Hegny Jun 06 '16 at 11:49