Friday, May 22, 2009

XSLT to XML

Displaying XML Data

Attach the XSLT Page to the XML Page

Once your XSLT page is finished, you must attach it to the XML page. When you use Dreamweaver to attach the page, Dreamweaver inserts a link to the XSLT page at the top of the XML page.

The XML page is the page to which your site visitors will browse when viewing the page online. This is because they must browse to the "content" page containing the data (the XML file), instead of the page that contains the styles (the XSLT page).

The XML and XSL files you use for client-side transformations must reside in the same directory. If they don't, the browser will read the XML file and find the XSLT page for the transformation, but will fail to find assets (style sheets, images, and so on) defined by relative links in the XSLT page.

  1. With the xml_menu.xsl page open in the Document window, open the Bindings panel (Window > Bindings) if it isn't already open.
  2. In the Bindings panel, double-click on Schema for specials.xml to open the specials.xml file. (You must double-click the words, and not the page icon.)
  3. Select Commands > Attach an XSLT Stylesheet.
  4. In the Attach an XSLT Stylesheet dialog box, click the Browse button, browse to the xml_menu.xsl page, select it, and click OK.
  5. Click OK to close the Attach an XSLT Stylesheet dialog box.

    Browsing to the XSL file to attach an XSLT stylesheet

    Figure 16. Browsing to the XSL file to attach an XSLT stylesheet

    Dreamweaver inserts the reference to the XSLT page at the top of the XML document.

    The reference to the XSLT page at the top of the XML document

    Figure 17. The reference to the XSLT page at the top of the XML document

  6. Save the specials.xml page.
  7. Preview the XML page (not the XSLT page) in a browser by pressing F12 (Windows) or Option+F12 (Macintosh). The XML page is displayed in a browser, styled with the XSLT page you created.

    The XML page displayed in a browser, styled with the XSLT page you created

    Figure 18. The XML page displayed in a browser, styled with the XSLT page you created

    (+) View larger

Remember, your site visitors will browse to the XML page (not the XSLT page) once you've deployed both pages to your server. For more information, see About client-side XSL transformations.

No comments:

Post a Comment