Node icon in a jsTree tree with font-awesome

Colet picture Colet · Jan 1, 2014 · Viewed 11.5k times · Source

I have a tree structure using jsTree, like this:

<div id="jstree">
        <ul>
           <li>Root 1
             <li> Child 1</li>  
           </li>   
        </ul>
</div>

I would like to put icons of font-awesome for the roots and children. Here is explained how to do it with bootstrap, below and example:

 <li data-jstree='{"icon":"glyphicon glyphicon-leaf"}'>Child</li>

I tried by doing this:

<li data-jstree='{"icon":"fa fa-user fa-2x"}'>

and this is the error that the browser tells me:

Invalid character (:) in expression "icon":"fa fa-user fa-2x"

I should also mention that I am using XML and XSL.

Does anyone have an idea about this issue?

Answer

Martin Honnen picture Martin Honnen · Jan 2, 2014

If you have <li data-jstree='{"icon":"fa fa-user fa-2x"}'> literally in XSLT code then I think you want <li data-jstree='{{"icon":"fa fa-user fa-2x"}}'> instead to prevent the XSLT engine from processing the attribute value as an attribute value template.