Using XML and XSLT to Personalize a Web Site Part 4: Dynamic Style Sheets and User Customized Layout
Building the Final Style Sheet Using DOM
At this point, we have the user's choices, but no way to implement them. What we need to do is build the additional template just as if it were any other XML document (by adding elements and attributes) and then add the template to the original style sheet document. We can then use the altered style sheet document to transform the content.
The choices the user has made will determine the structure of the template element we build. Remember, we're trying to build something along the lines of the following:
<xsl:template match="content"> <table> <tr class="toprow"> <td class="leftcell"><xsl:apply-templates select="weather"/></td> <td class="rightcell"><xsl:apply-templates select="schedules"/></td> </tr> <tr> <td colspan="2"><hr /></td> </tr> <tr> <td colspan="2"><xsl:apply-templates select="gossip"/></td> </tr> </table> </xsl:template>