[ANN] XPathView + XSLT-Support 1.0


I'm happy to announce the release of a new and heavily improved version of the XPathView
plugin. Inspired by the suggestions from Gordon Tyler (thank you!), the interactive XPath
evaluation is now capable of handling multi-line expressions, syntax coloring, validation
and completion, which is built on top of the new Language-API in IDEA 5.0.

The expression dialog now comes with two different modes, a simple (one-line) mode and an
advanced one with a multi-line editor and the ability to adjust namespace mappings and to
define variables. There's also the ability to list XPath matches in the Find Usages View,
making it possible to compare results, and to make use of the now implemented document()
-function for cross-document queries.

Additionally, the XSLT-Support features the same validation and completion for XPath
expressions inside XSLT documents, plus navigation and renaming for variables and named
XSLT templates. A file is recognized as an XSLT script if its top level tag name is
"stylesheet" from the XSLT namespace "http://www.w3.org/1999/XSL/Transform".

(This is heavily based on unpublished APIs. In case you experience any problems, please
make sure that it's not the plugin's fault before filing a JIRA issue. For that purpose,
the XSLT support can be disabled in the plugin's settings)

Known issues:
- Renaming enforces Java identifier rules, i.e. '-' is not an allowed character.
IDEA 5.0.1 will have an API to fix that.
- All expressions are rendered with bold text inside XSLT documents. The only way to fix
that is setting the default style for XML attribute values to non-bold.

The plugin is available through IDEA's Plugin Manager and at http://plugins.intellij.net
The full source code is included under the Apache License.

I hope you enjoy using it.

Sascha

13 comments
Comment actions Permalink

Excellent! I really like the Usages View. Very useful when I've got a
long list of matches that I need to scan/check. Synthax highlighting and
completion is amazing!

Here's a few things that I noticed/thought of while playing with it:

- When the cursor is in a part of the expression highlighted as an
error, it should show the error text somewhere in the dialog. Having to
go grab the mouse to hover over the text is tiresome ;)

- While evaluating the expression with "Show results in Usage View"
turned on, if the file is large it can take quite a few seconds to
finish and the UI is frozen while doing so. It should probably display a
progress/please wait dialog and perform the search on another thread.

- Pressing Enter in the middle of an expression in multi-line mode
leaves the cursor in an unexpected position on the new line, i.e. not
the beginning.

- It's highlighting tag and attribute names in the expression as "not
part of the document" but they are and the expression evaluation works.
If I add a trailing '/', the last tag name is no longer highlighted as
an error.

- Using Ctrl-Space and then Tab to complete a tag or attribute name
appends a space after the name, but using Ctrl-Space and Enter doesn't.

- In the completion list (and in the text), some functions are bolded
but some are not. Why?

- In the Usages View, "123 matchs" should be spelled as "matches". ;)

- It would be nice to have a button in the Usages View to edit and
re-evaluation the expression like the Structural Search.

- The labels on the up/down buttons in multi-line mode confused me until
I realised that they were meant to step through the history and not the
found occurrences.

- The icon for tags should probably have a transparent background
instead of white.

- Smart Completion, Ctrl-Shift-Space, would be cool if it could suggest
only the tag names or attribute names available at that point in the
expression. For example, if the DTD describes that tag 'foo' may only
contain tags 'bar' and 'baz', then smart completion should only suggest
those two and not 'foo' as well.

- In multi-line mode, when using the keyboard shortcuts Ctrl-Alt-Up/Down
to move within the history, the textfield loses focus and I have to
press Tab to get back there to continue editing.

Thanks,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Quick clarification:

- Smart Completion, Ctrl-Shift-Space, would be cool if it could suggest
only the tag names or attribute names available at that point in the
expression. For example, if the DTD describes that tag 'foo' may only
contain tags 'bar' and 'baz', then smart completion should only suggest
those two and not 'foo' as well.


... when used at the end of the following expression: //foo/

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Gordon Tyler wrote:

Excellent! I really like the Usages View. Very useful when I've got a
long list of matches that I need to scan/check. Synthax highlighting and
completion is amazing!


Thanks for the excellent feedback Gordon!

Here's a few things that I noticed/thought of while playing with it:

- When the cursor is in a part of the expression highlighted as an
error, it should show the error text somewhere in the dialog. Having to
go grab the mouse to hover over the text is tiresome ;)


You can press Ctrl-F1 (View -> Error Description) to get the tooltip, but I've been
thinking of adding some kind of status bar as well. But probably not in the near future.

- While evaluating the expression with "Show results in Usage View"
turned on, if the file is large it can take quite a few seconds to
finish and the UI is frozen while doing so. It should probably display a
progress/please wait dialog and perform the search on another thread.


Just put that on the TODO list.

- Pressing Enter in the middle of an expression in multi-line mode
leaves the cursor in an unexpected position on the new line, i.e. not
the beginning.


That seems to be the default behavior when editing custom languages when no formatter is
supplied. I had hoped to get away without implementing one...

- It's highlighting tag and attribute names in the expression as "not
part of the document" but they are and the expression evaluation works.
If I add a trailing '/', the last tag name is no longer highlighted as
an error.


That's because the trailing '/' is a syntax error which causes the validation to stop. Can
you provide some details about what names are flagged as not part of the document, such as
if they contain any wild Unicode characters or namespaces? Does the document have
default-namespaces declarations (]]>)? Is a schema or DTD attached?

- Using Ctrl-Space and then Tab to complete a tag or attribute name
appends a space after the name, but using Ctrl-Space and Enter doesn't.


You're right, that shouldn't be in there. Too much playing around...

- In the completion list (and in the text), some functions are bolded
but some are not. Why?


The bold functions are the predefined node-type tests that aren't regular functions:
node(), comment(), text(), processing-instruction(). I thought it makes sense to highlight
them.

- In the Usages View, "123 matchs" should be spelled as "matches". ;)


I only supply "match" here. That's a limitation of IDEA's pluralization algorithm ;)
http://www.jetbrains.net/jira/browse/IDEA-4428

- It would be nice to have a button in the Usages View to edit and
re-evaluation the expression like the Structural Search.


Good idea. I guess the "Sorry, no match" dialog could use such a button as well.

- The labels on the up/down buttons in multi-line mode confused me until
I realised that they were meant to step through the history and not the
found occurrences.


That's adapted from IDEA's debugger eval window. But you're right, the tooltips should be
changed.

- The icon for tags should probably have a transparent background
instead of white.


You know, it's easier to use what's already there than to do it yourself ;) But I will see
what I can do as I don't like that myself either.

- Smart Completion, Ctrl-Shift-Space, would be cool if it could suggest
only the tag names or attribute names available at that point in the
expression. For example, if the DTD describes that tag 'foo' may only
contain tags 'bar' and 'baz', then smart completion should only suggest
those two and not 'foo' as well.


I'll see what is possible. Smart Completion is not part of the Language API but a separate
action. The whole thing might be tricky to implement anyway (at least for non-trivial
location paths). If I need a new challenge some time I'll think of it.

- In multi-line mode, when using the keyboard shortcuts Ctrl-Alt-Up/Down
to move within the history, the textfield loses focus and I have to
press Tab to get back there to continue editing.


Yeah right, that's a problem. I'll try to fix it.

Sascha

0
Comment actions Permalink

Sascha Weinreuter wrote:
>> - Pressing Enter in the middle of an expression in multi-line mode
>> leaves the cursor in an unexpected position on the new line, i.e. not
>> the beginning.


That seems to be the default behavior when editing custom languages when
no formatter is supplied. I had hoped to get away without implementing
one...


Sascha I will gladly help you with a formatter if you like. Formatting is
totally simple, even though JavascriptLanguage does it in a funny, complicated
way. I just have one Block subclass, and it looks like JSBlock, except without
all the visitors and stuff, just some simple methods. getSpacing is mostly all
you need to implement.

0
Comment actions Permalink

Thanks for the offer Keith, but actually I failed to reproduce the behavior Gordon
described. The textfield behaves like a normal text-editor for me, i.e. new lines are
indented to the first non-whitespace position of the previous line.

Gordon, can you give me any hint how to reproduce this bad cursor positioning?

Sascha

0
Comment actions Permalink

Gordon Tyler wrote:

- It's highlighting tag and attribute names in the expression as "not
part of the document" but they are and the expression evaluation works.
If I add a trailing '/', the last tag name is no longer highlighted as
an error.


I think I found the reason. Once again, this is IDEA's weird behavior of using the DTD's
system URI as the default namespace of a document which I believe is incorrect. I'll add a
workaround for that.

Sascha

0
Comment actions Permalink

Sascha Weinreuter wrote:

Gordon, can you give me any hint how to reproduce this bad cursor positioning?


Type the following expression into the multiline textfield:

//select[contains(@path,"WebLogic")]

And then press Enter with the cursor positioned before "WebLogic". It
produces the following with | being the position of the cursor:

//select[contains(@path,
"We|bLogic")]

If one presses enter at the end of the expression instead, it just moves
to the next line and indents by 2 spaces.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Sascha Weinreuter wrote:

That's because the trailing '/' is a syntax error which causes the
validation to stop. Can you provide some details about what names are
flagged as not part of the document, such as if they contain any wild
Unicode characters or namespaces? Does the document have
default-namespaces declarations (<foo xmlns="...">)? Is a schema or DTD
attached?


The document has a DTD with just a SYSTEM identifier. No schema or
namespaces. Tag and attribute names consist of lowercase ASCII letters
and '-'.

>> - The icon for tags should probably have a transparent background
>> instead of white.


You know, it's easier to use what's already there than to do it yourself
;) But I will see what I can do as I don't like that myself either.


But of course 8)

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Sascha Weinreuter wrote:

I think I found the reason. Once again, this is IDEA's weird behavior of using the DTD's
system URI as the default namespace of a document which I believe is incorrect. I'll add a
workaround for that.


Yeah that is weird. A document with no namespace declared is in the ""
namespace, AKA No Namespace. DTD system URIs have nothing to do with
namespaces, they shouldn't be using that.

Or are you not talking about XML Namespaces?

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0
Comment actions Permalink

Gordon Tyler wrote:

Type the following expression into the multiline textfield:

//select[contains(@path,"WebLogic")]

And then press Enter with the cursor positioned before "WebLogic". It
produces the following with | being the position of the cursor:

//select[contains(@path,
"We|bLogic")]


Thanks, I see the problem now, but this clearly is an IDEA bug as it can be reproduced
even with plain text files: http://www.jetbrains.net/jira/browse/IDEA-4452

Sascha

0
Comment actions Permalink

Gordon Tyler wrote:

Or are you not talking about XML Namespaces?


No, I am talking about XML Namespaces. See my inquiry about that behavior here:
http://www.intellij.net/forums/thread.jsp?forum=23&thread=138483&tstart=0&trange=15

There's already a workaround in place that eliminates those implicit namespaces for
expression evaluation. I'll see if I can add that to the expression validation as well.

Sascha

0
Comment actions Permalink

Sacha, I'm very new to XSLT. I created a file test.xsl like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

And the tag and URI is highlighted in red. Did I do something wrong?

Thanks

0
Comment actions Permalink

Keith Lea wrote:

Sacha, I'm very new to XSLT. I created a file test.xsl like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

And the tag and URI is highlighted in red. Did I do something wrong?


No, absolutely not. The plugin does not provide the resource (the XML Schema) that IDEA
would like to have here. Though the idea to let the plugin provide one is worth to
consider, there isn't a standard schema for XSLT available. All those that I have tried so
far have different shortcomings so I'm not sure if the plugin should favor one.
The plugin just checks if the root element's namespace is
"http://www.w3.org/1999/XSL/Transform", it doesn't care if IDEA knows the resource or not.

Now that IDEA 5.0.1 is released I'll throw out another version this week. I hope to manage
to come up with some demo/documentation on the XSLT support as well.

Sascha

0

Please sign in to leave a comment.