# XPath expression generation

Procedure: Enable the XPathView + XSLT plugin

This functionality relies on the [XPathView + XSLT](https://plugins.jetbrains.com/plugin/12478-xpathview--xslt)  plugin, which  is bundled and enabled in IntelliJ IDEA   by default. If the relevant features are not available, make sure that you did not disable the plugin.

> **Note:**
> The XPathView + XSLT plugin is available by default only in IntelliJ IDEA  with the Ultimate subscription. For IntelliJ IDEA, you need to install the XPathView + XSLT plugin as described in [Plugins](managing-plugins.html).

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Open the Installed tab, find the XPathView + XSLT plugin, and select the checkbox next to the plugin name.

This action computes a unique XPath expression that matches the currently selected node in the document. The action is available from the main menu (`View | Unique Path`) and the editor context menu (Show Unique XPath). The action is only enabled when the caret is placed on an element that a useful expression can be generated for.

> **Tip:**
> The generated expression in the popup can be selected and copied into the clipboard for further use.

If a simple XPath expression like `/root/something/else` doesn't produce a unique result, the action has two strategies to make it unique:

* If the non-unique node is an element, the action looks for attributes with the name `id`, `name`, and attributes that are of ID type, as defined by the document's DTD or XML Schema. For example: `/root/something[@id="foo"]/else`

* For nodes other than elements (comments, processing instructions), or if the above rule doesn't produce a unique result, the index of the node inside its parent is appended. For example: `/root/something/else[2]`

