Thursday, February 4, 2010

The Daily Monthly

From the author of Cognitive Daily we have the The Daily Monthly. Each month a new topic but each day a new post (http://dailymonthly.com/)

Sunday, January 24, 2010

Cognitive Daily comes to a close

Cognitive Daily, one of the best physcology blogs around, announced they will no longer be posting anything new.
I've been reading Cognitive Daily since I was in high school and I'm very saddened to see it go.

Tuesday, January 5, 2010

Useful google search tip

One way to avoid Google getting "too smart" about your search query is to purposely misspell words. Sometimes I've found more relevant results when I do that. The misspelling has to be close to the original word though.

Sunday, January 3, 2010

xslt: != vs not()

I made a minor change to my xslt file. I often write "stub questions" in my FAQ to remind myself to answer them. I added a simple attribute to the "item" element

<xs:attribute name="stub" default="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="true"/>
<xs:enumeration value="false"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>


This creates an optional attribute "stub" that is a string which could either be "true" or "false" and is by default "false".

That wasn't too hard to figure out. The harder part was getting my XSLT file to only display non-stub questions.

My first try was <xsl:if test="@stub != 'false'"> (I used != because of the default).
This however never showed any of my questions. It turns out that != doesn't work when an element doesn't exist. After asking around on IRC <xsl:if test="not(@stub = 'true')"> appears to be the correct way to do things.

Wednesday, December 30, 2009

The Schema file for my FAQ

Here is my .xsd file.

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

This is where I define the faq element. This is my "root" element. It has two attributes which I use to store version information (version, and editDate). It contains a series of sections.

<xs:element name="faq">
<xs:complexType>
<xs:sequence>
<xs:element ref="section" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required" />
<xs:attribute name="editDate" type="xs:string" use="required" />
</xs:complexType>
</xs:element>


This where I define the item element (I need to change the item and section definitions)
Each item contains an id, a question, an answer, and possibly multiple "see also" links.

<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="question" maxOccurs="1" />
<xs:element ref="answer" maxOccurs="1" />
<xs:element ref="see" minOccurs="0" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
</xs:complexType>
</xs:element>

Each section contains multiple items as well as a title.

<xs:element name="section">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="title" type="xs:string" use="required" />
</xs:complexType>
</xs:element>

Each question is a plain string of text.
I had to resort to a weird trick for answers (to allow HTML) so I defined them as a mixed type.

<!-- describe things in a section -->
<xs:element name="question" type="xs:string" />

<xs:element name="answer">
<xs:complexType mixed="true" />
</xs:element>

Each see element gets converted to the text "see also ..." with a link to the question. The section id, question id are attributes of the see element.

<xs:element name="see">
<xs:complexType mixed="true">
<xs:attribute name="question" type="xs:NMTOKEN" use="required" />
<xs:attribute name="section" type="xs:NMTOKEN" use="required" />
</xs:complexType>
</xs:element>

</xs:schema>

Tuesday, December 29, 2009

XML + XSLT --> HTML

I was (am) putting together a FAQ for my classmates. As I started writing it my first pick of format was synamtically valid HTML. I picked definition lists for the question list. My problem was that I needed to repeat certain information constantly. The "back to top" link, the "see also" link format, and a few other things.

After looking around I decided to write my FAQ in XML and write a simple python program to convert it to HTML. When I converted my entire FAQ to XML (a pain in of itself) I wrote a python program to convert it. I realized though that making a simple change to my XML spec (for example adding a "section" part) would require a reworking of my entire python script.

"Even more research" later I found XSLT. When I read the description (converting from XML to another format) I realized that it is exactly what I need. Anyway my FAQ is now written in a reason format (XML with a tag for each section, item, question, and answer) and is converted to HTML using a simple XSLT file.

I'll try post more about how I got some of the cooler features working soon.