I want a way to format my study notes, taking an input file and outputting a clean, HTML file. I taught myself basic XML and XSTL today (and have prior knowledge of HTML and CSS) to accomplish this. So I would have a simple XML file with the note content, such as the following: \[code\]<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="http://stackoverflow.com/questions/15548224/stylesheet.xsl"?> <root> <heading>Programming Fundamentals 48023</heading> <section> <subheading>Classes and Objects</subheading> <point>Something about classes</point> <point>Some else about classes</point> <codeBlock> <text>How to create an instance of a class</text> <code>Class class = new Class();</code> </codeBlock> <point>Something about objects</point> . . . </section> <section> <subheading>Methods</subheading> <point>Something about methods</point> <codeBlock> <text>How to define a method</text> <code>modifiers returnType methodName() { . . . }</code> </codeBlock> . . . </section> . . .</root> \[/code\]The XML document should divide my notes into an abitrary number of sections, each with a subheading, and an arbitrary number of dot points and dot points with differently formatted blocks of code. Then, to format the XML document, a have a XSLT stylesheet (with HTML and CSS and such) that looks somewhat like this: \[code\]<?xsl version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html> <head> <title><xsl:value-of select="root/heading" /></title> <style> body {font-family:Tahoma; } div {width:800px; margin-left:auto; margin-right:auto; } h1 {color:#6FA5FD; border-bottom: 1px dotted #333333; text-indent:64px; } h2 {color:#6FA5FD; border-bottom: 1px dotted #333333; text-indent:96px; } pre {width:640px; border-style:dotted; border-width:1px; border-color:#333333; background-color:#CCCCFF; } ul {list-style-type:square; color:#6FA5FD; } li span {color:#000000; font-size:10; } </style> </head> <body> <div><!-- - - - - - - - - CONTENT STARTS HERE - - - - - - - - --><h1><xsl:value-of select="root/heading" /></h1><xsl:for-each select="root/section"> <h2><xsl:value-of select="subheading" /></h2> <xsl:for-each select="point"> <ul> <li><span> <xsl:value-of select="." /> </span></li> </ul> </xsl:for-each> <xsl:for-each select="codeBlock"> <ul> <li><span> <xsl:value-of select="./text" /> <pre> <xsl:value-of select="./code" /> </pre> </span></li> </ul> </xsl:for-each></xsl:for-each><!-- - - - - - - - - CONTENT ENDS HERE - - - - - - - - --> </div> </body></html></xsl:template></xsl:stylesheet> \[/code\]So the XML element becomes a formatted HTML element, the XML element becomes a formatted HTML element. This is great. Then the XML tag groups the dot points and code blocks, and so the dot points simply become list items with blue bullets and black text, and the code blocks are formatted in a HTML element. I'm having some problems, though:
-I don't have a way of having dot points with different levels of indentation. So I can't have a dot point that says, say, "Classes", and then have a couple of dot points underneath that one, indented slightly, that talk about what a class is in one point, naming conventions in another point, etc. I'd GUESS the solution would have something to do with making some new XML elements, such as point2, which would be formatted as:
-If, in my XML document, I define the various dot points and code blocks in a particular order (say, point, point, codeBlock, point, codeBlock, point), the resulting HTML file after the XSLT stylesheet does its work has all the points bunched together, and THEN all the codeBlocks (say, point, point, point, point, codeBlock, codeBlock instead). I understand WHY this happens; my XSLT document loops through all the XML elements, and THEN through all the XML elements. I'd guess the solution would have something to do with looping through all the child nodes of a element, and outputting one thing if the next element is a element, and outputting another thing if the next element is a element. Any ideas? Feel free to suggest a restructuring of either the XML or the XSLT documents. Maybe I should be using attributes for indentation or to distinguish between points and codeBlocks? Thankyou!!
-I don't have a way of having dot points with different levels of indentation. So I can't have a dot point that says, say, "Classes", and then have a couple of dot points underneath that one, indented slightly, that talk about what a class is in one point, naming conventions in another point, etc. I'd GUESS the solution would have something to do with making some new XML elements, such as point2, which would be formatted as:
- POINT
- POINT
-If, in my XML document, I define the various dot points and code blocks in a particular order (say, point, point, codeBlock, point, codeBlock, point), the resulting HTML file after the XSLT stylesheet does its work has all the points bunched together, and THEN all the codeBlocks (say, point, point, point, point, codeBlock, codeBlock instead). I understand WHY this happens; my XSLT document loops through all the XML elements, and THEN through all the XML elements. I'd guess the solution would have something to do with looping through all the child nodes of a element, and outputting one thing if the next element is a element, and outputting another thing if the next element is a element. Any ideas? Feel free to suggest a restructuring of either the XML or the XSLT documents. Maybe I should be using attributes for indentation or to distinguish between points and codeBlocks? Thankyou!!