Transforming RSS into HTML and WAP II (2/2) - exploring XML | WebReference

Transforming RSS into HTML and WAP II (2/2) - exploring XML

Transforming RSS into HTML and WAP II

WML output

The Wireless Markup Language (WML) is a smaller and less powerful variant of HTML, conceived as the display markup for mobile phones and PDAs. Details can be found in column12.

Differences between HTML and WML

For our little example the following differences are relevant: So we develop a sister style sheet to RSS2HTML, called RSS2WML, that transforms the same RSS input into the WML format instead of HTML:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:output method="wml"/>
We changed the output method, although WML is not a recognized method yet and therefore currently ignored. We're planning ahead for when this will change.
  <xsl:template match="/">
    <WML><CARD ID="id1" TITLE="RSS newsfeed">
      <xsl:apply-templates/>
    </CARD></WML>
  </xsl:template>
Here we change the familiar structure of HTML and BODY into the WML version of WML and CARD.
  <xsl:template match="channel">
    <DO TYPE="accept">
      <xsl:attribute name="LABEL">
        <xsl:value-of select="title"/>
      </xsl:attribute>
      <GO>
      <xsl:attribute name="HREF">
        <xsl:value-of select="link"/>
      </xsl:attribute>
      </GO>
    </DO>
  </xsl:template>
  <xsl:template match="item">
    <DO TYPE="accept">
      <xsl:attribute name="label">
        <xsl:value-of select="title"/>
      </xsl:attribute>
      <GO>
      <xsl:attribute name="HREF">
        <xsl:value-of select="link"/>
      </xsl:attribute>
      </GO>
    </DO>
  </xsl:template>
  <xsl:template match="text()"/>
</xsl:stylesheet>
Finally we need to replace the TABLE and A anchor formatting with the DO/GO pair of tags specified in WML. The finished product is RSS2WML. If you have a WAP-enabled mobile phone or a WAP development toolkit you can look at the WML output.

Conclusion

XSL is a flexible solution for converting an XML-based input format such as RSS into various output formats. The case study here demonstrated the transformation into HTML with CSS and WAP/WML. Non-XML based output such as RTF, PDF, GIF etc. is also possible, and we might get back to this topic in a later installment of this column.

http://www.internet.com

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column16/2.html
Created: Aug 01, 2000
Revised: Aug 01, 2000