xslt

The [xslt] context allows the application of an XSL style sheet to an XML document and thus 'transform' the XML data into any format required (usually HTML).

Parameters

ParameterDescription
xslrefNamed reference to a previously compiled block of XSL source.
xslsourceURL path to an external XSL document. This is an alternative to using the xslref parameter. Meaning that it is possible to use the [xslt] context without having used the [xsl] context to pre-compile XSL source code. However, if you plan to use the same XSL code several times throughout the template, then it would be more efficient to compile the XSL source code once, using [xsl], then just use the XSL object reference when needed.
xmlsourceURL reference to an external XML document on which to apply the XSL transformation. If this parameter is supplied, then any in-line XML code that exists between the [xslt] tags will be ignored.
Select all the 'CD' nodes in example-file.xml and transform the results into an HTML table, with the 'text' data of each CD node tree displayed in the table rows.

Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
[xsl var=xsl_var1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <h2>My CD Collection</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Title</th>
            <th>Artist</th>
          </tr>
          <xsl:for-each select="CATALOG/CD">
            <tr>
              <td><xsl:value-of select="TITLE"/></td>
              <td><xsl:value-of select="ARTIST"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
[/xsl]
[xslt xslref=xsl_var1][include file=example-file.xml][/xslt]

Or using a link to an external XML stylesheet.

Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml and the external style sheet example-xml-styles.inc
[xslt xslsource=example-xml-styles.xsl&xmlsource=example-file.xml][/xslt]
Results: Using either method, the results are the same

My CD Collection
TitleArtist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tylor
Greatest Hits Dolly Parton
Still got the blues Gary More
ErosEros Ramazzotti
One night only Bee Gees
Sylvias Mother Dr.Hook
Maggie May Rod Stewart
Romanza Andrea Bocelli
When a man loves a woman Percy Sledge
Black angel Savage Rose
1999 Grammy Nominees Many
For the good times Kenny Rogers
Big Willie style Will Smith
Tupelo Honey Van Morrison
Soulsville Jorn Hoel
The very best of Cat Stevens
Stop Sam Brown
Bridge of Spies T`Pau
Private Dancer Tina Turner
Midt om natten Kim Larsen
Pavarotti Gala Concert Luciano Pavarotti
The dock of the bay Otis Redding
Picture book Simply Red
Red The Communards
Unchain my heart Joe Cocker

Download some further XSL styling examples: more-example-xml-styles.xsl

Appending XML to a WebDNA database


This example uses XSLT to generate WebDNA [append] code to append the XML data to a WebDNA database.

Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
[xsl var=xsl_var1][!]
[/!]%5Breplace db=music.db[url]&[/url]eqTITLEdata=[url]&[/url]append=T%5D[!]
[/!]TITLE=[url]&[/url][!]
[/!]ARTIST=
%5B/replace%5D
[/xsl]
[text]result=[unurl][xslt xslref=xsl_var1][include file=example-file.xml][/xslt][/unurl][/text]
Results: The [text] variable 'results' contains the following:
[replace db=music.db&eqTITLEdata=Empire Burlesque&append=T]TITLE=Empire Burlesque&ARTIST=Bob Dylan[/replace]
[replace db=music.db&eqTITLEdata=Hide your heart&append=T]TITLE=Hide your heart&ARTIST=Bonnie Tylor[/replace]
[replace db=music.db&eqTITLEdata=Greatest Hits&append=T]TITLE=Greatest Hits&ARTIST=Dolly Parton[/replace]
[replace db=music.db&eqTITLEdata=Still got the blues&append=T]TITLE=Still got the blues&ARTIST=Gary More[/replace]
[replace db=music.db&eqTITLEdata=Eros&append=T]TITLE=Eros&ARTIST=Eros Ramazzotti[/replace]
[replace db=music.db&eqTITLEdata=One night only&append=T]TITLE=One night only&ARTIST=Bee Gees[/replace]
[replace db=music.db&eqTITLEdata=Sylvias Mother&append=T]TITLE=Sylvias Mother&ARTIST=Dr.Hook[/replace]
[replace db=music.db&eqTITLEdata=Maggie May&append=T]TITLE=Maggie May&ARTIST=Rod Stewart[/replace]
[replace db=music.db&eqTITLEdata=Romanza&append=T]TITLE=Romanza&ARTIST=Andrea Bocelli[/replace]
[replace db=music.db&eqTITLEdata=When a man loves a woman&append=T]TITLE=When a man loves a woman&ARTIST=Percy Sledge[/replace]
[replace db=music.db&eqTITLEdata=Black angel&append=T]TITLE=Black angel&ARTIST=Savage Rose[/replace]
[replace db=music.db&eqTITLEdata=1999 Grammy Nominees&append=T]TITLE=1999 Grammy Nominees&ARTIST=Many[/replace]
[replace db=music.db&eqTITLEdata=For the good times&append=T]TITLE=For the good times&ARTIST=Kenny Rogers[/replace]
[replace db=music.db&eqTITLEdata=Big Willie style&append=T]TITLE=Big Willie style&ARTIST=Will Smith[/replace]
[replace db=music.db&eqTITLEdata=Tupelo Honey&append=T]TITLE=Tupelo Honey&ARTIST=Van Morrison[/replace]
[replace db=music.db&eqTITLEdata=Soulsville&append=T]TITLE=Soulsville&ARTIST=Jorn Hoel[/replace]
[replace db=music.db&eqTITLEdata=The very best of&append=T]TITLE=The very best of&ARTIST=Cat Stevens[/replace]
[replace db=music.db&eqTITLEdata=Stop&append=T]TITLE=Stop&ARTIST=Sam Brown[/replace]
[replace db=music.db&eqTITLEdata=Bridge of Spies&append=T]TITLE=Bridge of Spies&ARTIST=T`Pau[/replace]
[replace db=music.db&eqTITLEdata=Private Dancer&append=T]TITLE=Private Dancer&ARTIST=Tina Turner[/replace]
[replace db=music.db&eqTITLEdata=Midt om natten&append=T]TITLE=Midt om natten&ARTIST=Kim Larsen[/replace]
[replace db=music.db&eqTITLEdata=Pavarotti Gala Concert&append=T]TITLE=Pavarotti Gala Concert&ARTIST=Luciano Pavarotti[/replace]
[replace db=music.db&eqTITLEdata=The dock of the bay&append=T]TITLE=The dock of the bay&ARTIST=Otis Redding[/replace]
[replace db=music.db&eqTITLEdata=Picture book&append=T]TITLE=Picture book&ARTIST=Simply Red[/replace]
[replace db=music.db&eqTITLEdata=Red&append=T]TITLE=Red&ARTIST=The Communards[/replace]
[replace db=music.db&eqTITLEdata=Unchain my heart&append=T]TITLE=Unchain my heart&ARTIST=Joe Cocker[/replace]

These results are then able to be 'appended' to the music.db

Example WebDNA code:
[interpret]
  [result]
[/interpret]