Re: [xsl] nested templates?

Subject: Re: [xsl] nested templates?
From: Alex Black <enigma@xxxxxxxxxxxxxxxx>
Date: Wed, 16 May 2001 12:58:47 -0700
below is a real world example of for-each. (first 'document')
this works.

which is fine, but I far prefer nested templates, because that implies that
I can _import_ those templates wherever I like, and build up complex
documents out of little sub-formatters.

Thus the "<field>" -> <input type="foo"> example.

Or, if you use the XML below, an example:

what if I wanted an external handler for the element "bookmark" because it
occurs in 100 of my templates? I read a little on the import syntax, but I
need a little extra push :)

I'm warming up to this language rapidly, after you get over the amazing
verbosity of the syntax, it works quite well, actually :)


Oh, minor:
does anyone know how to make sablot freaking _not_ output a full xml header
declaration, _and_ put xmlns attributes in _every_ tag? Also, as you can see
in the output html, there is no preservation of whitespace, and no apparent
way of having comments sent out unless you wrap them in !CDATA.

Gotta get rid of those ns declarations, bigtime code bloat :)

(look at the bottom)

_alex

-------------------------------------------------------

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>

<!-- template ::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<xsl:template match="/">

<!-- select each folder -->
<xsl:for-each select="//folder">
<!-- section - - - - - - - - - - - - - - - - - - -->
<table border="0" cellpadding="1" cellspacing="0" bgcolor="#FF6600"
width="100%"><tr><td valign="top">
<table border="0" cellpadding="4" cellspacing="0" width="100%"
bgcolor="#DEDEDE"><tr><td valign="top">
<a>
<xsl:attribute name="href"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@name"/>
</a><br />
</td></tr></table></td></tr></table>
<p/>

<!-- select each bookmark -->
<xsl:for-each select="bookmark">
<img src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/>
<a>
<xsl:attribute name="href"><xsl:value-of select="href"/></xsl:attribute>
<xsl:value-of select="title"/>
</a>
<br/>
</xsl:for-each>
<!-- /select each bookmark -->
<p/>

</xsl:for-each>
<!-- /select each folder -->

</xsl:template>
<!-- /template ::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->

</xsl:stylesheet>



-------------------------------------------------------


<?xml version="1.0"?>

<bookmarks>
    <folder name="books">
        <bookmark>
            <title>Foo</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Wired</title>
            <href>http://www.wired.com</href>
        </bookmark>
        <bookmark>
            <title>Fee</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Fah</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Man</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Chala</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>poofoo</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
    </folder>
    <folder name="movies">
        <bookmark>
            <title>Cheesehead</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>mangles</title>
            <href>http://www.wired.com</href>
        </bookmark>
        <bookmark>
            <title>Fatso</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Beefy-kitty</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Attick-GOPHER</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>Foobar</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
        <bookmark>
            <title>hell!</title>
            <href>http://www.yahoo.com</href>
        </bookmark>
    </folder>
</bookmarks>


-------------------------------------------------------



<?xml version="1.0" encoding="UTF-8"?><table
xmlns:fo="http://www.w3.org/1999/XSL/Format"; border="0" cellpadding="1"
cellspacing="0" bgcolor="#FF6600" width="100%"><tr><td valign="top"><table
border="0" cellpadding="4" cellspacing="0" width="100%"
bgcolor="#DEDEDE"><tr><td valign="top"><a
href="books">books</a><br/></td></tr></table></td></tr></table><p
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Foo</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.wired.com";>Wired</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Fee</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Fah</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Man</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Chala</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>poofoo</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><p
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><table
xmlns:fo="http://www.w3.org/1999/XSL/Format"; border="0" cellpadding="1"
cellspacing="0" bgcolor="#FF6600" width="100%"><tr><td valign="top"><table
border="0" cellpadding="4" cellspacing="0" width="100%"
bgcolor="#DEDEDE"><tr><td valign="top"><a
href="movies">movies</a><br/></td></tr></table></td></tr></table><p
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Cheesehead</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.wired.com";>mangles</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Fatso</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Beefy-kitty</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Attick-squirill</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>Foobar</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><img
xmlns:fo="http://www.w3.org/1999/XSL/Format";
src="/resources/images/binarycloud/misc/000000.gif" alt="-" width="3"
height="3" hspace="2" vspace="2" border="0" align="middle"/><a
xmlns:fo="http://www.w3.org/1999/XSL/Format";
href="http://www.yahoo.com";>hell!</a><br
xmlns:fo="http://www.w3.org/1999/XSL/Format"/><p
xmlns:fo="http://www.w3.org/1999/XSL/Format"/>





--
alex black, ceo
enigma@xxxxxxxxxxxxxxxx

the turing studio, inc.
http://www.turingstudio.com

vox+510.666.0074
fax+510.666.0093



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread