Embed XSL in Behaviors

Embed XSL in Behaviors

Browsers Targeted: Internet Explorer 5

Behaviors let you create specific functionality within custom HTML tags. XSL (Extensible Stylesheet Language) lets you transform a block of XML into some form of output, including HTML. The two would seem to be ideally suited for one another, but hauling around an XSL file reference begins to weaken the power of such a combination. However, a nice feature of behaviors is that you can embed HTML within them, and more specifically, you can embed XML data islands inside of a behavior. Once embedded, you can retrieve the data island using its id property, then use XMLDocument to retrieve a reference to the XML document contained within.

For example, consider a behavior that takes a generic list of elements within a container element. The behavior will convert such a list into a selection list box, with the id of the container becoming the id of the

 			Red		Green		Blue		Yellow		Orange		Brown		Violet		Black		White			
Option Behavior

For this behavior, the code contains an XSL data island named filter. When the behavior is initialized, the filter is read through its ID (“filter”) and stored in an XSL variable. When a refresh is called (as it is automatically when the control first loads), the initial data island passed by reference from the HTML document calls transformNode, taking as its argument the XSL document. This will apply the template to the document, which is in turn output to the innerHTML of the behavior’s calling element.



Share the Post: