Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@hiro_literal

XHTML5からXHTML Basic1.1への変換

More than 1 year has passed since last update.

XHTMLからフィーチャーフォン向けへの変換

今さらだが、フィーチャーフォン(ガラケー)用にWebサイトを変換するXSLTを投稿してみる。そのうち失われる内容なので記念碑みたいなものか。
文字中心の簡易なサイトならそれほど困らないはず。
Shift_JISの方がフィーチャーフォンには良いのだが、変換できない文字(UTF-8限定の文字)があるとエラーを起こすので下処理が必要になる。
かつては3キャリア別々にして絵文字も分けたりしていたけれど、今はこの程度のざっくり変換でも良いんじゃないかとか。


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:htm="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="htm">
<xsl:output method="xml"
encoding="UTF-8"
version="1.0"
indent="no"
doctype-public="-//W3C//DTD XHTML Basic 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"/>

<xsl:template match="htm:head">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="htm:link[@rel='stylesheet']|htm:title"/>
</xsl:element>
</xsl:template>

<xsl:template match="htm:link[@rel='stylesheet']">
<link rel="stylesheet" type="text/css">
<xsl:attribute name="href"><xsl:value-of select="concat(substring-before(@href,'css/'),'css/mobile.css')"/></xsl:attribute>
</link>
</xsl:template>

<xsl:template match="htm:meta|htm:link|htm:script|htm:style|htm:header|htm:figure/htm:p|node()[self::text()='&#10;']"/>

<xsl:template match="htm:time[parent::htm:article]|htm:figcaption|htm:canvas">
<p><xsl:apply-templates select="@href|node()"/></p>
</xsl:template>

<xsl:template match="htm:div|htm:section|htm:aside|htm:nav|htm:article|htm:figure|htm:blockquote|htm:span|htm:abbr|htm:cite|htm:code|htm:dfn|htm:ins|htm:q|htm:samp|htm:time">
<xsl:apply-templates select="@href|node()"/>
</xsl:template>

<xsl:template match="htm:h1[htm:span]">
<h1><xsl:value-of select="text()"/><br/><xsl:value-of select="htm:span"/></h1>
</xsl:template>

<xsl:template match="htm:a[starts-with(@href,'#')]">
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:template match="htm:table">
<table>
<xsl:apply-templates select="htm:caption"/>
<xsl:apply-templates select="htm:thead/*"/>
<xsl:apply-templates select="htm:tbody/*"/>
<xsl:apply-templates select="htm:tfoot/*"/>
</table>
</xsl:template>

<xsl:template match="htm:dt[htm:a]">
<xsl:copy>&#9632;<xsl:apply-templates select="@href|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="htm:dt">
<xsl:copy>&#9661;<xsl:apply-templates select="@href|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="htm:img">
<xsl:value-of select="@alt"/>
</xsl:template>

<xsl:template match="@href|node()">
<xsl:copy><xsl:apply-templates select="@href|node()"/></xsl:copy>
</xsl:template>

</xsl:stylesheet>
2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?