|
Red Squirrel Reflections
Dave Hoover explores the psychology of software development
|
|
Sat, 15 Jan 2005Quote Manager Project -- Day 2 An ongoing pet project blog...So now I know how to read XML data and, using Java 5.0, transform it into HTML. I also have an XSL style sheet that duplicates the look and feel of my current quotes page. Again I find myself wondering what to do next. Again I will put on my customer hat and consider what I want. Let's look at the original plan:
OK, sorting in XSL is easy.
I just had to add two lines beneath my <xsl:for-each select="quotes/quote"> <xsl:sort select="quoter"/> <xsl:sort select="author"/>But that doesn't do what I want. First of all, it sorts by first name. Secondly, it puts all of the quoter-less quotes first, and then adds the quote by Weinberg last. As my fellow ThoughtWorker Dave Wood would say: "Boooo." Actually, this is good. It looks like I'm going to need to change my XML data structure in order to allow for the sorting I need. I'm glad I chose to do this task before the XML update spike, since the data format would have changed. Pulling into the station... OK, I've changed the XML data format to break quoter and author names down into first and last names like: <quoter url="http://www.geraldmweinberg.com/"> <first>Gerald</first><last>Weinberg</last> </quoter>But that still doesn't solve the problem of wanting to sort by quoter, since most quotes just have authors. As the customer, I'm OK with sorting by authors for now, so I'll change the sorting tags to: <xsl:for-each select="quotes/quote"> <xsl:sort select="author/last"/> <xsl:sort select="author/first"/>I'm checking in. My next task is to spike reading and updating the XML file from Java. I wonder if I could use some of my XSL transformation code? It looks like the first half of my previous spike could come in handy...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse("sample.xml");
But I'm not familiar with how to use a Document.
Back to the Java XML tutorial...
|