3

I just exported my whole LiveJournal-Blog with an exporting application to an XML file. Reason for this is to archive it all and preserve for future generations. I want to make a simple layout file for it, so I can read the posts and go all nostalgic. It looks like any regular XML file:

<livejournal>
  <entry>
    <itemid>1</itemid>
    <eventtime>Date/time</eventtime>
    <subject>Subject Line</subject>
    <event>The actual post</event>
    <allowmask>0</allowmask>
    <current_mood>current mood</current_mood>
    <current_music>current mood</current_music>
    <taglist>comma, separated, tags</taglist>
    <comment>
      <itemid>2433</itemid>
      <eventtime>Date</eventtime>
      <subject>Subject Line</subject>
      <event>The actual comment</event>
      <author>
        <name>Commenter</name>
        <email>Commenter@email</email>
      </author>
    </comment>
  </entry>
  <entry>
</livejournal>

So far everything is nice and good. The problem occurs when I try to make an xsl file for it. The <event> tag in the xml file contains not only text, but also HTML. And to boot, HTML written in 2004 and generated by all sorts of meme generators. So the code doesn't evaluate worth much. We see lovely tags as <table border=1 width=300> and tons of unclosed img, input, br and hr tags.

The current export have replaced all <> with &lt;&gt; so it evaluates as an xml file. What I want to do is to be able to view the XML file with all the intended HTML tags. So <b></b> makes things bold. But I have no idea how to do so since &lt;b&gt;&lt;/b&gt; doesn't evaluate properly.

<event>I ate a &lt;b&gt;tasty&lt;/b&gt; cucumber</event>

outputs

I ate a <b>tasty</b> cucumber

rather than

I ate a tasty cucumber

Is there a way to get around this? Since changing all the lt, gt in the xml file to <> makes it not evaluate due to the bad HTML. And I don't feel like going through 700+ posts to make stuff evaluate properly by hand.

1 Answers1

1

A <xsl:value-of select="entry" disable-output-escaping="yes"/> will do the trick.

Example XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="/">
        <html>
            <head></head>
            <body>                
                <xsl:apply-templates select="*"/> 
            </body>
        </html>
    </xsl:template>

    <xsl:template match="*">
        <xsl:apply-templates select="*"/>
    </xsl:template>

    <xsl:template match="event">
        <div class="event">
            <xsl:value-of select="." disable-output-escaping="yes"/>                        
        </div>
    </xsl:template>

</xsl:stylesheet>

Run on:

<livejournal>
    <entry>
        <itemid>1</itemid>
        <eventtime>Date/time</eventtime>
        <subject>Subject Line</subject>
        <event>I ate a &lt;b&gt;tasty&lt;/b&gt; cucumber</event>
        <allowmask>0</allowmask>
        <current_mood>current mood</current_mood>
        <current_music>current mood</current_music>
        <taglist>comma, separated, tags</taglist>
        <comment>
            <itemid>2433</itemid>
            <eventtime>Date</eventtime>
            <subject>Subject Line</subject>
            <event>The actual comment</event>
            <author>
                <name>Commenter</name>
                <email>Commenter@email</email>
            </author>
        </comment>
    </entry>
</livejournal>

Results in:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   </head>
   <body>
      <div class="event">I ate a <b>tasty</b> cucumber</div>
      <div class="event">The actual comment</div>
   </body>
</html>
Paul Ryan
  • 1,509
  • 12
  • 26
  • It doesn't work in Chrome and FireFox, but it works in internet explorer! I'm just happy if I got some way of viewing it, so it works for me. Thank you very much for your help! – Mattias Storm May 30 '13 at 18:03
  • Are you trying to run this as a local file? If so you might be running into the Same Origin Policy (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript?redirectlocale=en-US&redirectslug=JavaScript%2FSame_origin_policy_for_JavaScript ).You may need to run it from a server for Chrome and Firefox to be able to parse. I haven't tried it there though, it was tested with saxon and xalan. – Paul Ryan May 30 '13 at 18:49
  • I stood up a quick webserver (node.js) to serve the xml pages here and when that was done it works fine on chrome but not on firefox. On firefox it looks to have parsed fine when looking in the inspector is just didn't know how to render (must be an issue with the xsl renderer in firefox). – Paul Ryan May 30 '13 at 20:18