Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr2425 :: Intro to XSL

A brief introduction to XSL and xsltproc

<< First, < Previous, , Latest >>

Hosted by Klaatu on 2017-11-17 is flagged as Clean and is released under a CC-BY-SA license.
docbook, xml, xsl. 2.
The show is available on the Internet Archive at: https://archive.org/details/hpr2425

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:41:42

general.

Sure, you can use pandoc to process your Docbook XML, but why not learn a little XSL this weekend?

Requirements

You must have xsltproc installed. It's available from your software repository.

Here is some sample XML for you:


<xml version="1.0">
  <para>
    My name is <author>Foo</author>.
  </para>

  <para>
    You're listening to <emphasis role="bold">Hacker Public
    Radio</emphasis>.
  </para>
</xml>

And here's the complete XSL as demonstrated:


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

  <xsl:template match="para">
    <p><span><xsl:apply-templates/></span></p>
  </xsl:template>

  <xsl:template match="emphasis">
    <em><xsl:apply-templates/></em>
  </xsl:template>

  <xsl:template match="emphasis[@role='bold']">
    <strong><xsl:apply-templates/></strong>
  </xsl:template>

  <xsl:template match="author" name="host">
    <xsl:choose>

      <xsl:when test="$host = 'Klaatu'">
        <xsl:text>Klaatu</xsl:text>
      </xsl:when>

      <xsl:when test="$host = 'Gort'">
        <xsl:text>Gort</xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Links


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2017-11-19 22:49:47 by Dave Morriss

This was really interesting

I enjoyed this a lot. It was very clearly explained and the example was helpful.

I tried to understand XSL back in 2012 when writing Bash scripts to let me download music from Magnatune. They held their catalogue in XML at that time (now it's in a SQLite database) and I used xsltproc and XSL to extract stuff. I didn't find any very clear explanations of what could be done in XSL at that time, though I winged it by copying examples and using trial and error.

Your links seem to fill in many of the gaps in my understanding, so thanks for them too.

Dave

Comment #2 posted on 2017-11-21 07:37:38 by Klaatu

Re: This was really interesting

Glad you enjoyed in! I just can't wait for your LaTeX episode!

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?