Netbeans autocomplete XSLT/HTML

I downloaded Netbeans 8.0.1 to create some XSLT files. Here is a small example:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Title</th>
        <th style="text-align:left">Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

The autocomplete feature of Netbeans works complete without problems, if you have a simple XSLT file or a simple HTML file. But if you mix up those two files, the autocomplete feature just works for XSLT .
Beginning with the <html> tag, i don't have autocomplete anymore, even not for the XSLT tags at the end of the file.
Does anyone know if this is a bug or just some settings to use autocomplete for HTML and XSLT ?


Holy GNU, after a whole afternoon on that, I managed to get both XSL and HTML auto-complete working on the same XSL file.

Download an XSD version of HTML5

HTML is not XML, so we must take a look on XHTML5 (HTML serialized as XML). I've taken the XSD from there

Tell netbeans to use it

The xhtml namespace http://www.w3.org/1999/xhtml must use the XSD we've downloaded. So, in Tools → DTD & XML Schema → User catalog, add a local Schema where the System ID is http://www.w3.org/1999/xhtml and the URI is the xhtml5.xsd you've downloaded .

You may need to restart netbeans (I actually restated it so many times I cannot tell whether it's required or not).

Use the xhtml namespace in the XSL

Now, in the XSL, tell that you're using the xhtml namespace with the attribute xmlns="http://www.w3.org/1999/xhtml" on the root node.

<xsl:stylesheet version="1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >

You could also have added this xmlns attribute to each most-top-level html node (aka, each html node that has no html node in their ancestors). You can also use xmlns:html on the root node, and use <html:*> instead of <*> nodes. It's useful if you have multiple namespaces like HTML+SVG+MathML+XSL .

Enjoy html auto-complete

You should then have the auto completion for html. It requires that you explicitly type the first html tag, but once inside an html tag, the auto complete works (so, if you're making a table inside a xsl:template , you'll still have to type the <table> but once inside, auto complete will suggest things like <caption> , <thead> and so on).


What about auto-complete XSL inside the HTML?

It requires an edit in the xhtml's XSD. We must declare the XSL namespace in the XSD using xmlns:xsl="http://www.w3.org/1999/XSL/Transform" on XSD's root node. Then, we must tell in the XSD that every HTML node can contain an XSL node. This is done by using <xs:any namespace="http://www.w3.org/1999/XSL/Transform" processContents="skip"/> in all elements groups <xs:group> .

Once these edits are done, the XSD says "Every HTML node can contain an element from XSL's namespace", so Netbeans's auto-complete will suggest XSL nodes too.

You can download the edited XSD I'm using here: http://xenos.reinom.com/stackoverflow/xhtml5.xsd


In case you're wondering, I made a long detailed response so you can do the same if you want to mix XSL and SVG or XSL and any other XML-XSDed format.

链接地址: http://www.djcxy.com/p/63646.html

上一篇: 更好的自动完成SCSS的崇高

下一篇: Netbeans自动完成XSLT / HTML