Anch Posted November 25, 2008 Share Posted November 25, 2008 Apologies in advance if this is the wrong forum - I'll put it in XML as well - and if my question is mind-bogglingly ignorant. I'm a student of website authoring and need help with my project. The idea is to create a style guide for a magazine using a single xml file, but break it into separate web pages for each letter of the alphabet. I don't want 26 xslt files, however - how can I tell the xslt to generate only the results for a specific letter? I've already set up the dtd with attributes for initials, and imagine I need to do something with URLs, but can't find out what or how...Many thanks in advance,Anch WarlowBirkbeck College, LondonHere's my xml code, with v basic data in it so far, and the xslt I've done so far with a very rough and unsuccessful attempt at solving the problem. Please be kind... <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE style SYSTEM "styleguide.dtd"><?xml-stylesheet type="text/xsl" href="REVstyleguide.xslt"?><style> <entry position="copy" initial="c"> <heading>C</heading> <subheading>Clichés</subheading> <copy>blah blah</copy> </entry> <entry position="copy" initial="a"> <heading>A</heading> <subheading>Acronyms</subheading> <copy>blah blah</copy> </entry> <entry position="display" initial="a"> <heading></heading> <subheading>Abronyms</subheading> <copy>blah blah</copy> </entry></style> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><?xslt version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="initial"><!-- in here I want something that'll read the url for the initial--> <script type="text/javascript"> document.write(location.hash); </script></xsl:variable> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="styleguide.css" /> <title>hello! magazine style guide</title> </head> <body class="wrapper"> <!-- start of page header --> <div id="header"> <h1>magazine style guide</h1> </div> <!-- end of page header --> <!-- start of primary nav bar --> <ul id="navbar"> <!-- use list to create horizontal nav bars --> <li><a href="index.htm" id="homebutton" title="to home page">Home</a> </li> <li><a href="undercon.htm" id="intranetbutton" title="to iintranet home page">Intranet home</a></li> <li><a href="" id="backissuesbutton" title="to back issues finder">Back issues finder</a></li> <li><a href="" id="phonesbutton" title="to internal phone directory">Internal phone nos</a></li> </ul> <!-- end of primary navigation bar --> <!-- main content --> <div id="middlecol"> <xsl:for-each select="style/entry[@position='copy'][@initial='$initial']"> <xsl:sort order="ascending"/> <h1><xsl:value-of select="heading"/></h1> <h3><xsl:value-of select="subheading"/></h3> <p><xsl:value-of select="copy"/></p> </xsl:for-each> </div> <div id="rightcol"> <xsl:for-each select="style/entry[@position='display'][@initial='$initial']"> <xsl:sort order="ascending"/> <h1><xsl:value-of select="heading"/></h1> <h3><xsl:value-of select="subheading"/></h3> <p><xsl:value-of select="copy"/></p> </xsl:for-each> </div> <!-- bottom nav bar --> <!--this bit needs work to find out how to parse the attribute through the url--> <ul id="bottomnav"> <li><a href="styleguide.xml?../entry/initial='a'" id="abutton" title="to a page">A</a></li> <li><a href="styleguide.xml?initial=b" id="bbutton" title="to b page">B</a></li> </ul> <!-- end bottom nav bar --> <!-- footer --> <div id="footer"> © hello! magazine Last updated: <!-- #BeginDate format:Am1 -->October 28, 2008 <!-- #EndDate --> <a href="mailto:awarlow@hellomagazine.com">Contact</a> </div> <!-- end of footer --> <!-- end of main content --> </body> </html> </xsl:template> </xsl:stylesheet> Link to comment Share on other sites More sharing options...
aalbetski Posted November 25, 2008 Share Posted November 25, 2008 This is probably far too advanced if you're a beginner and turning in homework, but I accomplished your task using XSL Keys and Muenchian grouping. It may be good for you to analyze this for an advanced way of doing this. I trimmed down the XML to get rid of unneeded data, the initial is taken from the subheading node itself, no need for the meta-data <xml id="xmlSource"> <style> <entry> <subheading>Clichés</subheading> <copy>blah blah</copy> </entry> <entry> <subheading>Acronyms</subheading> <copy>blah blah</copy> </entry> <entry> <subheading>Abronyms</subheading> <copy>blah blah</copy> </entry> </style> </xml> <xml id="xslStyle"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"> <xsl:key name="FirstInitial" match="entry" use="substring(subheading,1,1)"/> <xsl:output method="html" /> <xsl:template match="/"> <xsl:for-each select="//entry[count(. | key('FirstInitial',substring(subheading,1,1))[1]) = 1]"> <xsl:sort select="." order="ascending" /> <xsl:variable name="Initial" select="substring(subheading,1,1)"/> <hr/> <xsl:value-of select="$Initial" /> <p/> <xsl:for-each select="//subheading[substring(.,1,1)=$Initial]"> <xsl:sort select="." order="ascending" /> <xsl:value-of select="."/><br/> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> </xml> Link to comment Share on other sites More sharing options...
Anch Posted November 26, 2008 Author Share Posted November 26, 2008 Many thanks - you're right, this is going beyond what we're studying, but I think it could be really useful anyway as I work towards a solution. Really appreciate you taking the time on it! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.