Jump to content

I Probably Wasn't Very Clear...


Anch

Recommended Posts

Apologies again, I missed something that was probably quite crucial in my earlier post - and also apologies again 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 want to use navigation buttons for each letter of the alphabet, but I don't want 26 different URLs and/or 26 xslt files. 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 within the URLs, but can't find out what or how... NB my class doesn't cover .asp or xsl groups or very advanced stuff, so the more basic the better...Many thanks in advance,Anch WarlowBirkbeck College, LondonHere's my xml code, with v basic data in it so far (and nb the "position" attribute relates to some display requirements, which work and I'm happy with), 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="styleguide.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: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']">						<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']">						<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

XSLT by itself will generate an HTML, text, or XML file. One file. If you need to create more than one, you will need a calling program to invoke the XSLT and pass an argument to it for the letter you wantHowever you are processing the transformation is where you should do this. The pseudo-code for Javascript could be1. Load XML into DOM2. Load XSLT into DOM3. Iterate though all letters with Javascript loop4. Pass each letter (one at a time) to XLST as parameter5. XMLDOM processes XLST against XML and generates a single output pagerepeat 4 and 5 as part of step 3.The code I gave you earlier can easily be modified to act on a single letter.

Link to comment
Share on other sites

		<style>			<entry>				<subheading>Zebras</subheading>				<copy>blah blah</copy>			</entry>			<entry>				<subheading>Zbronyms</subheading>				<copy>blah blah</copy>			</entry>			<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>			<entry>				<subheading>Dbronyms</subheading>				<copy>blah blah</copy>			</entry>		</style>

		<xsl:stylesheet			xmlns:xsl="http://www.w3.org/1999/XSL/Transform"			xmlns:msxsl="urn:schemas-microsoft-com:xslt"			version="1.0">		<xsl:param name="letter" />		<xsl:output method="html" />		<xsl:template match="/">			<xsl:for-each select="//subheading[substring(.,1,1)=$letter]">				<xsl:sort select="." order="ascending" />				<xsl:value-of select="."/><br/>			</xsl:for-each>		</xsl:template>		</xsl:stylesheet>

var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"var fso		=  new ActiveXObject("Scripting.FileSystemObject");var xmlDoc   =	 new ActiveXObject("Msxml2.DOMDocument.4.0")xmlDoc.async=false;WScript.Echo(xmlDoc.load("C:\\Documents\\dev\\XSLT\\Letter\\Subheadings.xml"));var xslSource   =	 new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0")xslSource.async=false;WScript.Echo(xslSource.load("C:\\Documents\\dev\\XSLT\\Letter\\Subheadings.xslt"));xslSource.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.4.0")objTransformer.stylesheet = xslSource.documentElementvar objProcessor = objTransformer.createProcessor()	objProcessor.input = xmlDoc	for (var i=0;i<26;i++)	{		var letter = letters.substr(i,1)		objProcessor.addParameter("letter",letter,"")		objProcessor.transform()		var sOutput =  objProcessor.output		var writefile	= fso.CreateTextFile(letter + ".HTML",true);		writefile.Write(sOutput);		writefile.close();		}

Link to comment
Share on other sites

OK, I think I see where you're going with that. I need to do a lot more reading round it... but I really, really appreciate the help.

		<style>			<entry>				<subheading>Zebras</subheading>				<copy>blah blah</copy>			</entry>			<entry>				<subheading>Zbronyms</subheading>				<copy>blah blah</copy>			</entry>			<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>			<entry>				<subheading>Dbronyms</subheading>				<copy>blah blah</copy>			</entry>		</style>

		<xsl:stylesheet			xmlns:xsl="http://www.w3.org/1999/XSL/Transform"			xmlns:msxsl="urn:schemas-microsoft-com:xslt"			version="1.0">		<xsl:param name="letter" />		<xsl:output method="html" />		<xsl:template match="/">			<xsl:for-each select="//subheading[substring(.,1,1)=$letter]">				<xsl:sort select="." order="ascending" />				<xsl:value-of select="."/><br/>			</xsl:for-each>		</xsl:template>		</xsl:stylesheet>

var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"var fso		=  new ActiveXObject("Scripting.FileSystemObject");var xmlDoc   =	 new ActiveXObject("Msxml2.DOMDocument.4.0")xmlDoc.async=false;WScript.Echo(xmlDoc.load("C:\\Documents\\dev\\XSLT\\Letter\\Subheadings.xml"));var xslSource   =	 new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0")xslSource.async=false;WScript.Echo(xslSource.load("C:\\Documents\\dev\\XSLT\\Letter\\Subheadings.xslt"));xslSource.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.4.0")objTransformer.stylesheet = xslSource.documentElementvar objProcessor = objTransformer.createProcessor()	objProcessor.input = xmlDoc	for (var i=0;i<26;i++)	{		var letter = letters.substr(i,1)		objProcessor.addParameter("letter",letter,"")		objProcessor.transform()		var sOutput =  objProcessor.output		var writefile	= fso.CreateTextFile(letter + ".HTML",true);		writefile.Write(sOutput);		writefile.close();		}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...