Is there a Ctags tool for viewing / navigating XSLT code in Vim?

You need to easily navigate and view XSLT files using Vim. Just like ctags can be used with C / C ++ source code. A good solution will allow you to install scripts, etc. Just for yourself or run them directly from within Vim. I hate having to exit vim just to search for a function definition or text search.

I searched for a few hours and came up with some good examples like "ack". Apparently this can be integrated with vim using ack.vim. But check it out right.

Essentially, I should be able to go through a maze of .xsl files that include other .xsl files and use functions, templates. Any suggestions?

+5
source share
3 answers

I found the answers of kipelovets and GuruM useful and developed this solution that combines their advice.

.ctags:

--langdef=xslt
--langmap=xslt:.xsl
--regex-xslt=/<xsl:template[^>]+name=\"([-a-zA-Z0-9_:]+)\"( +mode="([^"]+)")?/\1 \2/n,namedtemplate/i
--regex-xslt=/<xsl:template[^>]+match=\"([^"]+)\"( +mode="([^"]+)")?/\1     \2/m,matchedtemplate/i
--regex-xslt=/<xsl:apply-templates +select="([^"]{2,})"( +mode="([^"]+)")?/\1 \2/a,applytemplate/i
--regex-xslt=/<xsl:call-template +select="([^"]+)"( +mode="([^"]+)")?/\1 \2/c,calltemplate/i
--regex-xslt=/<xsl:variable[^>]+name=\"([-a-zA-Z0-9_]+)\"/\1/v,variable/i
--regex-xslt=/<xsl:function[^>]+name=\"([-a-zA-Z0-9_:]+)\"/\1/f,function/i
--regex-xslt=/<xsl:param[^>]+name=\"([-a-zA-Z0-9_:]+)\"/\1/p,parameter/i

Vim tag settings (which some people may find useful):

let g:tagbar_type_xslt = {
      \ 'ctagstype' : 'xslt',
      \ 'kinds'     : [
      \ 'n:templates (named)',
      \ 'm:templates (matched)',
      \ 'a:applied templates',
      \ 'c:called templates',
      \ 'f:functions',
      \ 'p:parameters',
      \ 'v:variables'
      \ ]
      \ }

This is better, but some issues that I still have include:

  • grouping patterns by their modes
  • spaces such as newlines between attributes for a template / variable, etc.
  • defining variables and parameters and applying call patterns and patterns
    • So, if you have several variables with the same name, but in different templates, the scope of which they are located is not fixed.
  • commented patterns, functions, variables and parameters

Best approach to future search:

  • xslt ,
  • xslt xslt.
+3

@GuruM

~/.ctags , :

--langdef=xslt
--langmap=xslt:.xsl
--regex-xslt=/<xsl:template[^>]+name=\"([-a-zA-Z0-9_:]+)\"/\1/f,function/i

AutoTag TagList:

let s:tlist_def_xslt_settings = 'xslt;f:function'    
+1

@Izap. , , . , , ( ).
:
1) : egrep 'pattern' *
2) - ~/.ctags.

--langdef=EXSLT
--langmap=EXSLT:.xsl
--regex-EXSLT=/<xsl:variable[ \t]+name=\"([-a-zA-Z0-9_]+)\"/\1/v,variable/i
--regex-EXSLT=/<func:function[ \t]+name=\"([-a-zA-Z0-9_:]+)\"/\1/f,function/i
--regex-EXSLT=/<xsl:template[ \t]+match=\"([/-a-zA-Z0-9_:]+)\"/\1/t,template/i

. () , \1 . xslt exslt .
, .
3) cd srcdir && ctags -R *
4) , , ctags 5) vim Ctrl-], ..
: "" ctags C- .

0

All Articles