• Home
  • About
  • Articles and Presentations
  • Contact Me
  • Upcoming Presentations

Library Web Chic

Resources for librarians who are interested in the application of web design and technologies in libraries

Feed on
Posts
Comments

An XSLT for Furl XML

Jul 20th, 2004 by Karen

An XSLT for Furl XML

A while back I mentioned the fact that I was using XML from Furl to drive the “Resources” portion of my site. I decided that since other people might want to do this and don’t know how I should probably post the code. To do this transform you need a couple of things. First, an XML parser and some sort of server-side scripting language are necessary. I'm using MSXML and ASP because my site lives on a Microsoft box. You can also use another parser and scripting language. I believe the latest version of PHP has an XML parser built-in. Once you have this there are two pieces of code you need to write. The first is the XSLT file that transforms your XML document into XHTML/HTML. Below is the code in my XSLT file. Because this is an XSLT file, it is platform independent.

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:fo=”http://www.w3.org/1999/XSL/Format”>
<xsl:output method=”html”/>
<xsl:param name=”topic”/>
<xsl:key name=”list” match=”entry” use=”topic” />

<xsl:template match=”/”>

<xsl:for-each select=”/archive/entry[generate-id(.)=generate-id(key('list',topic))]/topic”>
<!– Only process the item if it's
the first time we've seen the Name –>
    <xsl:sort order=”ascending” select=”.” />

    <xsl:if test=”contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),translate($topic,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))”>
        <xsl:element name=”h3″>
            <xsl:value-of select=”.”/>
        </xsl:element>
        <xsl:for-each select=”key('list',.)”>
        <xsl:element name=”h4″>
            <xsl:element name=”a”>
            <xsl:attribute name=”href”>
                <xsl:value-of select=”@uri”/>
            </xsl:attribute>
            <xsl:value-of select=”@title”/>
            </xsl:element>
        </xsl:element>
        <xsl:element name=”p”>
            <xsl:value-of select=”description”/>
        </xsl:element>
        </xsl:for-each>
    </xsl:if>

</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

The second bit of code is the server-side scripting code that takes the XSLT file and the XML file, send them to the parser and transforms them on the fly. As I said before I'm using ASP to do this. Below is the ASP code that performs the task of bring together the XML file and XSL and sends them to the XML parser.

<%
set xslt = Server.CreateObject(”MSXML2.XSLTemplate.4.0″)
set xslDoc = Server.CreateObject(”Msxml2.FreeThreadedDOMDocument.4.0″)
set xmlDoc = Server.CreateObject(”Msxml2.DOMDocument.4.0″)
Dim xslProc
xslDoc.async = false
xslDoc.resolveExternals = false
xslDocName = “all_links.xsl”
xslParam = topic
xslDoc.load (Server.MapPath(xslDocName))
xslDoc.validateOnParse = False
set xslt.stylesheet = xslDoc
xmlDoc.async = false
xmlDoc.resolveExternals = false
xmlDoc.load (Server.MapPath(”exportXML.xml”))
set xslProc = xslt.createProcessor()
xslProc.input = xmlDoc
xslProc.addParameter “topic”, xslParam
xslProc.transform()
response.write xslProc.output
%>

Using these two bits of code I transform the XML version of my Furl archive into the resource pages on this site. Overall, it a pretty easy but power trick that helps me multi-purpose content I've in a variety of ways.

Posted in XML | No Comments

Comments are closed.

  • Recent Posts

    • This is why open source software rules
    • WorldCat Search API Terms of Service issues
    • Drupal Content Management and Community for your Library
    • Drupal modules I wish existed
    • The Views module for Drupal is AWESOME
    • Creating Database lists with Wordpress Link tool
  • Categories

    • AJAX (1)
    • BLeading Edge Thoughts (4)
    • Blogging (23)
    • Chat (3)
    • Coldfusion (2)
    • CSS (14)
    • Digital Libraries (3)
    • Findability (2)
    • General Thoughts (425)
    • Library Systems (16)
    • Linux (3)
    • LITA Top Tech Trends (1)
    • Mac (5)
    • Nifty Tools (6)
    • Notes from the Field (105)
    • Ongoing Projects (7)
    • open source software (6)
    • OpenURL (8)
    • Podcasting (1)
    • Presentations (1)
    • RSS (32)
    • Social Software (5)
    • Tech Configuration Tidbits (1)
    • Tech Demons (11)
    • Usability (11)
    • Web 2.0 (5)
    • Web Services (3)
    • Web Standards (1)
    • Wikis (7)
    • XHTML (3)
    • XML (19)
  • Archives

    • 2008
      • October
      • September
      • August
      • July
      • June
      • May
      • April
      • March
      • February
      • January
    • + 2007
      • December
      • November
      • October
      • September
      • August
      • July
      • June
      • May
      • April
      • March
      • February
      • January
    • + 2006
      • December
      • November
      • October
      • September
      • August
      • July
      • June
      • May
      • April
      • March
      • February
      • January
    • + 2005
      • December
      • November
      • October
      • September
      • August
      • July
      • June
      • May
      • April
      • March
      • February
      • January
    • + 2004
      • December
      • November
      • October
      • September
      • August
      • July
      • June
      • May
      • April
      • March
  • Pages

    • About
      • CV
    • Articles and Presentations
      • AJAX Presentation
      • Incorporating Web 2.0 into Library Websites
      • Library 2.0 and Web 2.0, Changing the Face of Professional Development
      • Mashing Up and Remixing the Library Website
      • Next Stop Blogging
      • Observing and Analysing Library Website User Behavior (CIL 2006 Postconference)
      • Open Source Software for Library Websites Presentation
      • Social Software for Reference Services Presentation
      • Ten News Items of Note for Libraries
      • TLA 2006 Presentation
      • Upcoming Presentations
      • Using Blogs for Internal Communications
      • Web 2.0, Library 2.0 and the Future of Libraries
      • WorldCat Wordpress Widget
    • Contact Me
    • Stories - Tutorials and Code Demonstrations
      • Feedburner
      • Incorporating XML Content Into Your Web site (ASP)
      • Making your blog friendly to mobile devices
      • Print Style sheets
      • Server-side and Client-side includes, explanations, applications, and examples
      • Web Server Log Analysis Tools and Tips
      • Wordpress and Tags
    • Tag Cloud
  • Meta

    • Log in
    • Valid XHTML
    • Powered by Wordpress
    • Get Firefox!
    • I See Blog People
    • AIM Status
  • Creative Commons License

    MistyLook made free by Web Hosting Bluebook