How to apply XSL style sheets to XML views

In this tip, I will show you an easy way to apply XSL (Extensible Style Language) style sheets to an XML view without the pain of creating numerous view templates.

If you have any XML views in your application, chances are you will be applying an XSL style sheet to them -- using complicated JavaScript routines. For presentation's sake, there is an easier way.

For example, let's say you have one XML view and six XSL style sheets. In this example, you will use a page to store your XSL.

First, create a form to be used as your view template. The form should be either HTML or text/XML. The form will be opened with a URL like this:

Your embedded view will be XMLVIEW, which is a formula computed using @URLQueryString("view").

At the top of the form, you will define the XML details -- including which style sheet to apply. Your computed value will be the @WebDbName of your database, plus @URLQueryString("XSL"), as shown below:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" 
href="<computed value>"?>

The XML style sheet line tells the browser to pre-format your XML with the XSL page you specified.

How you store the XSL in the database is up to you, but you could make it accessible to advanced users to enable them to manipulate data without needing to create any more views.

To finish, pass the name of the XSL file in the URL Query String and the browser does the rest.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: Extensible Markup Language
  • Reference Center: XML/Web services tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Ben Rodway. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    This was first published in February 2007

  • There are Comments. Add yours.

    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.