Subject: [xsl] XSLT review request From: Nathan Shaw <n8_shaw@xxxxxxxxx> Date: Mon, 20 Aug 2001 06:51:17 -0700 (PDT) |
Hi all.. I am wrapping up my first real XML/XSLT project. I have everything working pretty well and thought that it would be a good idea to post the XSLT here for review. I am definitely a newbie (although this list has helped bring me up to working speed somewhat quickly), so I am basically looking for any suggestions on pitfalls I may have fallen into or optimization techniques I could apply to increase the effeciency of the transformations. Thanks all! Direct replies appreciated (n8_shaw@xxxxxxxxx). XSLT: <?xml version="1.0" ?> <!-- XSLT Stylesheet for OBPR General Information web site Version 1.0 08/13/2001 Nathan Shaw (nshaw@xxxxxxxxxxx) --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" doctype-system="DTD/html4-transitional.dtd" omit-xml-declaration="yes" indent="no" /> <xsl:strip-space elements="*" /> <!--<xsl:preserve-space elements="..." />--> <xsl:template match="/"> <html xmlns:="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <title>NASA - SpaceResearch:OBPR - <xsl:value-of select="WebContent/Content/Header/@Title" /></title> <link rel="stylesheet" href="styles_general_info.css" type="text/css" /> <script language="javascript" type="text/javascript" src="../common/swap_image.js"></script> </head> <body bgcolor="#ffffff" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" onload="preLoad();"> <table border="0" cellpadding="0" cellspacing="0" width="760"> <tr><td bgcolor="#000000"> <table cellspacing="1" cellpadding="0" border="0" width="760"> <!--nasa logo and header graphic--> <tr valign="top"> <td colspan="3"><a href="http://www.nasa.gov/"><img src="../common/sub_nasa_logo.gif" width="54" height="50" border="0" alt="NASA Logo" /></a><a href="/"><img src="../common/sub_header2.gif" width="704" height="50" border="0" alt="NASA Space Research graphic" /></a></td> </tr> <!--top navigation--> <tr valign="top"> <td><a href="#"><img name="sub_general_info" src="../common/sub_general_info_on.gif" width="252" height="19" border="0" alt="General Information" /></a></td> <td><a href="#" onMouseOut="swap_image('../common/sub_research_projects.gif','sub_research_projects');" onMouseOver="swap_image('../common/sub_research_projects_on.gif','sub_research_projects');"><img name="sub_research_projects" src="../common/sub_research_projects.gif" width="252" height="19" border="0" alt="Research and Projects" /></a></td> <td><a href="#" onMouseOut="swap_image('../common/sub_fun_learning.gif','sub_fun_learning');" onMouseOver="swap_image('../common/sub_fun_learning_on.gif','sub_fun_learning');"><img name="sub_fun_learning" src="../common/sub_fun_learning.gif" width="252" height="19" border="0" alt="Fun and Learning" /></a></td> </tr> </table> <table cellspacing="1" cellpadding="8" border="0" width="760"> <!--left-hand navigation--> <tr valign="top"> <td bgcolor="#99cc99" width="160" rowspan="2"><a href="/general_info/what.html" class="mainnav">What is the OBPR?</a><br /> <a href="/general_info/news/news.html" class="mainnav">News</a><br /> <a href="/general_info/presentations/pres.html" class="mainnav">Presentations</a><br /> <a href="/general_info/articles/art.html" class="mainnav">Articles</a><br /> <a href="/general_info/contact.html" class="mainnav">Contact Information</a><br /> <a href="/general_info/faq.html" class="mainnav">FAQ's</a> </td> <!--header--> <td width="600" bgcolor="#99cc99"><span class="pageheader"><xsl:value-of select="/WebContent/Content/Header/@Title" /></span><br /> <xsl:for-each select="/WebContent/Navigation/SubMenu/SubMenuItem"> <!--subnavigation--> <a href="{@URL}" class="subnav"><xsl:value-of select="text()" /></a><xsl:if test="position()!=last()"> | </xsl:if> </xsl:for-each> <xsl:for-each select="/WebContent/Navigation/SubMenu/Image"><br /> <xsl:choose><xsl:when test="@LinkURL"><a href="{@LinkURL}"><img src="{@SourceURL}" width="{@Width}" height="{@Height}" align="{@Align}" name="{@Name}" border="{@Border}" alt="{@AltText}" /></a></xsl:when><xsl:otherwise><img src="{@SourceURL}" width="{@Width}" height="{@Height}" align="{@Align}" name="{@Name}" border="{@Border}" alt="{@AltText}" /></xsl:otherwise> </xsl:choose> </xsl:for-each> </td> </tr> <xsl:apply-templates select="/WebContent/Content" /> </table> <!-- footer --> <table cellspacing="0" cellpadding="5" border="0" width="760"> <tr> <td valign="top" bgcolor="#000000" width="600" class="footer"><a href="/contact.htm">NASA Headquarters Responsible Official: Code U</a><br /><a href="contact.htm">Curator: Office of Biological and Physical Research</a><br /><a href="http://www.nasa.gov/hqpao/privacy.html">NASA Privacy Statement</a></td> <td bgcolor="#000000" width="160" align="right"><a href="http://spaceresearch.nasa.gov/iso9k/iso9k.html"><img src="../common/iso9001_logo.gif" width="51" height="42" alt="ISO9001 Logo" border="0" /></a><a href="https://neptune.hq.nasa.gov/codeu_kic/"><img src="../common/kic_logo.gif" width="51" height="42" alt="KIC Logo" border="0" /></a></td> </tr> </table> </td></tr> </table> </body> </html> </xsl:template> <!-- content --> <xsl:template match="Content"> <tr> <td width="600" bgcolor="#ffffff"><xsl:apply-templates /></td> </tr> </xsl:template> <!--page header--> <xsl:template match="Header"> <xsl:apply-templates /> </xsl:template> <xsl:template match="HeaderText"> <xsl:if test="string()"><xsl:copy-of select="node()" /></xsl:if> </xsl:template> <!-- section --> <xsl:template match="Section"> <div id="{@Title}"><span class="sectionheader"> <xsl:choose> <xsl:when test="@URL"> <xsl:choose> <xsl:when test="@Anchor"><a href="{@URL}" name="{@Anchor}" class="anchor"><xsl:value-of select="@Title" /></a></xsl:when> <xsl:otherwise><a href="{@URL}" class="anchor"><xsl:value-of select="@Title" /></a></xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="@Anchor"><a name="{@Anchor}" class="anchor"><xsl:value-of select="@Title" /></a></xsl:when> <xsl:otherwise><xsl:value-of select="@Title" /></xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </span><br /><br /> <xsl:apply-templates /> <xsl:if test="not(position()=last())"> <hr size="1" noshade="noshade" width="520" align="center" /> </xsl:if></div> </xsl:template> <xsl:template match="SectionText"> <xsl:copy-of select="node()" /> </xsl:template> <!-- subsection --> <xsl:template match="SubSection"> <div id="{@Title}"><b> <xsl:choose> <xsl:when test="@URL"> <xsl:choose> <xsl:when test="@Anchor"><a href="{@URL}" name="{@Anchor}"><xsl:value-of select="@Title" /></a></xsl:when> <xsl:otherwise><a href="{@URL}"><xsl:value-of select="@Title" /></a></xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="@Anchor"><a name="{@Anchor}"><xsl:value-of select="@Title" /></a></xsl:when> <xsl:otherwise><xsl:value-of select="@Title" /></xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </b><br /> <xsl:apply-templates /> </div> </xsl:template> <xsl:template match="SubSectionText"> <xsl:copy-of select="node()" /> </xsl:template> <!-- list --> <xsl:template match="List"> <xsl:choose><xsl:when test="@URL"><b><a href="{@URL}"><xsl:value-of select="@Title" /></a></b></xsl:when><xsl:otherwise><xsl:if test="@Title"><b> <xsl:value-of select="@Title" /></b></xsl:if></xsl:otherwise></xsl:choose> <xsl:choose> <xsl:when test="@Type='Unordered'"> <ul><xsl:apply-templates /></ul> </xsl:when> <xsl:when test="@Type='Ordered'"> <ol><xsl:apply-templates /></ol> </xsl:when> <xsl:otherwise> <ul><xsl:apply-templates /></ul> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="ListItem"> <li> <xsl:choose> <xsl:when test="@URL"><a href="{@URL}"><xsl:value-of select="node()" /></a></xsl:when> <xsl:otherwise><xsl:value-of select="node()" /></xsl:otherwise> </xsl:choose> <xsl:if test="@Caption"> [<xsl:value-of select="@Caption" />]</xsl:if> </li> </xsl:template> <!-- image --> <xsl:template match="Image"> <xsl:choose> <xsl:when test="@LinkURL"><a href="{@LinkURL}"><img src="{@SourceURL}" width="{@Width}" height="{@Height}" align="{@Align}" name="{@Name}" border="{@Border}" alt="{@AltText}" /></a></xsl:when> <xsl:otherwise><img src="{@SourceURL}" width="{@Width}" height="{@Height}" align="{@Align}" name="{@Name}" border="{@Border}" alt="{@AltText}" /> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- table --> <xsl:template match="DataTable"> <table cellspacing="{@CellSpacing}" cellpadding="{@CellPadding}" border="{@Border}" width="{@Width}" height="{@Height}" summary="{@Summary}" align="{@Align}" bgcolor="{@BGColor}"> <xsl:if test="@Title"><caption><xsl:value-of select="@Title" /></caption></xsl:if> <xsl:apply-templates /> </table> </xsl:template> <xsl:template match="DataTableHeader"> <tr><xsl:apply-templates /></tr> </xsl:template> <xsl:template match="DataTableColumnHeader"> <th bgcolor="{@BGColor}" width="{@Width}" height="{@Height}" align="{@Align}" valign="{@VAlign}" rowspan="{@RowSpan}" colspan="{@ColSpan}"> <xsl:choose> <xsl:when test="@URL"><a href="{@URL}" class="anchor"><xsl:copy-of select="text()" /></a></xsl:when> <xsl:otherwise><xsl:copy-of select="node()" /></xsl:otherwise> </xsl:choose> </th> </xsl:template> <xsl:template match="DataTableRow"> <tr><xsl:apply-templates /></tr> </xsl:template> <xsl:template match="DataTableRowHeader"> <th bgcolor="{@BGColor}" width="{@Width}" height="{@Height}" align="{@Align}" valign="{@VAlign}" rowspan="{@RowSpan}" colspan="{@ColSpan}"> <xsl:choose> <xsl:when test="@URL"><a href="{@URL}" class="anchor"><xsl:copy-of select="text()" /></a></xsl:when> <xsl:otherwise><xsl:copy-of select="node()" /></xsl:otherwise> </xsl:choose> </th> </xsl:template> <xsl:template match="DataTableRowCell"> <td bgcolor="{@BGColor}" width="{@Width}" height="{@Height}" align="{@Align}" valign="{@VAlign}" rowspan="{@RowSpan}" colspan="{@ColSpan}"> <xsl:choose> <xsl:when test="@URL"><a href="{@URL}"><xsl:copy-of select="text()" /></a></xsl:when> <xsl:otherwise><xsl:copy-of select="node()" /></xsl:otherwise> </xsl:choose> </td> </xsl:template> </xsl:stylesheet> SAMPLE XML: <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE WebContent PUBLIC "-//Alex Pline/DTD OBPRWebContent//EN//" "../OBPRWebContent.dtd"> <?xml-stylesheet type="text/xsl" href="OBPRGeneralInfoWebContent.xsl"?> <WebContent> <Navigation> <MainMenu></MainMenu> <SubMenu> <SubMenuItem URL="strat.html#v">Mission</SubMenuItem> <SubMenuItem URL="strat.html#g">Goals</SubMenuItem> <SubMenuItem URL="strat.html#p">Philosophy</SubMenuItem> </SubMenu> </Navigation> <Content> <Header Title="OBPR Strategic Vision"> <HeaderText /> </Header> <Section Title="Mission" Anchor="v"> <SectionText>Conduct basic and applied research to support human exploration of space and to take advantage of the space environment as a laboratory for scientific, technological, and commercial research.</SectionText> <List> <ListItem URL="http://www.hq.nasa.gov/office/codez/plans/pl2000.pdf" Caption="3.18 MB pdf">NASA Strategic Plan</ListItem> <ListItem URL="http://www.hq.nasa.gov/office/codez/plans.html">NASA Planning Documents</ListItem> </List> </Section> <Section Title="Goals" Anchor="g"> <SectionText /> <List Type="Bulleted"> <ListItem>Enable Exploration: Conduct research to enable safe and productive human habitation of space</ListItem> <ListItem>Science: Use the space environment as a laboratory to test the fundamental principles of physics, chemistry, and biology</ListItem> <ListItem>Commerce: Enable and promote commercial research in space</ListItem> <ListItem>Outreach: Use space research opportunities to improve academic achievement and the quality of life</ListItem> </List> </Section> <Section Title="Philosophy" Anchor="p"> <SectionText /> <List Type="Bulleted"> <ListItem>To make use of the full spectrum of biological, physical, chemical and biomedical research, from basic research to applied research</ListItem> <ListItem>To build and strengthen strong involvement of the academic community in NASA's science and technology mission</ListItem> <ListItem>To provide the organization for facilitating the effective use of ISS facilities for targeted scientific and technology questions</ListItem> <ListItem>To provide the organization for transferring scientific and technology results for the benefit of Earth</ListItem> </List> </Section> </Content> </WebContent> ===== ---------------------------- Nathan Shaw Web Applications Developer iaffect http://www.iaffectonline.com http://www.iaffectTV.com ---------------------------- __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] fo:table, Corey Spitzer | Thread | [xsl] RES:, Daniel Dias Dos Sant |
Re: [xsl] XPath explorer, Mark Galbreath | Date | RE: [xsl] Assigning values to varia, Corey Spitzer |
Month |