This page describes how to use the Transform() function to convert XML data to HTML within Second Site.


The following information is intended for advanced users.

The Transform() function is useful when you have information that you want to maintain in XML, but publish in HTML. For example, consider an address list. You can keep the information in HTML, but it's not convenient: HTML does not include elements that are specific to the address data you might want to store. You may also want to publish a subset of the information, keeping telephone numbers or street addresses private, but HTML is not designed for that.

In XML, you can store all the information in an appropriate format:

    <name>John Doe</name>
    <sort-by>Doe, John</sort-by>
    <street>101 Main Street</street>
    <name>Jim Doe</name>
    <sort-by>Doe, Jim</sort-by>
    <street>101 Groovy Street</street>

Use NotePad or a similar text editor to save the text above in a file called "addresses.xml".

Then, using XSLT, you can convert it to HTML.

    <td>Jim Doe</td>
    <td>Cooltown, CA 99999</td>
    <td>John Doe</td>
    <td>Anytown, MA 02000</td>

Which might look like this:

Jim Doe Cooltown, CA 99999
John Doe Anytown, MA 02000

Note that the street address and telephone number are omitted, and the entries are sorted by the contents of the "SORT-BY" element. Such output would be easy to produce with XSLT.

Here's the XSLT to convert the XML above to the HTML above:

<xsl:stylesheet version="1.0"
<xsl:output method="html" indent="yes"
<xsl:template match="/document">
  <table class="grid">
    <xsl:apply-templates select="person">
      <xsl:sort select="sort-by"/>
<xsl:template match="person">
      <xsl:value-of select="name"/>
      <xsl:value-of select="city"/>
      <xsl:text>, </xsl:text>
      <xsl:value-of select="state"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="zip"/>

Use NotePad or a similar text editor to save the text above in a file called "addresses.xsl".

To see the XML above transformed into HTML, follow the steps below.

  1. Make an Include subfolder in the Input (-i) folder for your site if you do not already have one:
    • mysite.sdf
    • mysite-i
      • include
  2. Save the XML and XSL shown above in text files in the "include" folder:
    • mysite.sdf
    • mysite-i
      • include
        • addresses.xml
        • addresses.xsl
  3. Add a Custom Page User Item to your site and set the Main Content to the following script statement:
  4. Make the site.

The site should now include a custom page that shows an address list similar to the one shown above.

On This Page