今回は労働基準法令の中でもひときわ大部である、労働安全衛生規則を変換してみることにした。前回にも書いたように、労働安全衛生規則(以下「規則」とする)は、編、章、節、款といった様々な構成単位により成っていて、また、規則全体を木構造とみなすと、ノードによって深さがまちまち(つまり節のない章や款の無い節がある)だったりするので、割と扱いが面倒なのだった。というわけで僕のプログラミング力では冗長なコードしか書けなかったのだが、まあとりあえず出力自体は成功した。リンクのid名もとりあえずちゃんと付けられた。結果はこちら。
労働基準法のXMLをHTMLにしてみた(2)+α
前回のは各号列記が出力されなかったり色々問題があったので修正した。恐らくXSLTの肝であろうxsl:templateを活用したので割とコードがすっきりした(はず)。あとなんとなくバージョンを3.0にした。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsl xs fn">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="Law/LawBody"/>
</xsl:template>
<xsl:template match="Law/LawBody">
<html>
<head>
<title><xsl:value-of select="LawTitle"/></title>
<link href="sample.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1><xsl:value-of select="LawTitle"/></h1>
<div class="TOC">
<xsl:for-each select="TOC/TOCChapter">
<a>
<xsl:attribute name="href">#c<xsl:value-of select="@Num"/></xsl:attribute>
<xsl:value-of select="ChapterTitle"/>
</a>
<xsl:if test="count(TOCSection)!=0">
<xsl:for-each select="TOCSection">
<a>
<xsl:attribute name="href">#c<xsl:value-of select="../@Num"/>s<xsl:value-of select="@Num"/></xsl:attribute>
<xsl:attribute name="class">section</xsl:attribute>
<xsl:value-of select="SectionTitle"/>
</a>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</div>
<xsl:for-each select="MainProvision/Chapter">
<div class="chapter">
<h3>
<xsl:attribute name="id">c<xsl:value-of select="@Num"/></xsl:attribute>
<xsl:value-of select="ChapterTitle"/>
</h3>
<xsl:choose>
<xsl:when test="count(Section)=0">
<xsl:apply-templates select="Article"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="Section"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="Section">
<div class="section">
<h4 class="section_title">
<xsl:attribute name="id">c<xsl:value-of select="../@Num"/>s<xsl:value-of select="@Num"/></xsl:attribute>
<xsl:value-of select="SectionTitle"/>
</h4>
<xsl:apply-templates select="Article"/>
</div>
</xsl:template>
<xsl:template match="Article">
<div class="article">
<h6 class="article_title"><xsl:value-of select="ArticleTitle"/></h6>
<span class="caption"><xsl:value-of select="ArticleCaption"/></span>
<xsl:apply-templates select="Paragraph"/>
</div>
</xsl:template>
<xsl:template match="Paragraph">
<p class="paragraph">
<xsl:value-of select="ParagraphNum"/>
<xsl:value-of select="ParagraphSentence/Sentence"/>
</p>
<xsl:apply-templates select="Item"/>
</xsl:template>
<xsl:template match="Item">
<p class="item">
<xsl:value-of select="ItemTitle"/>
<xsl:value-of select="ItemSentence/Sentence"/>
<xsl:apply-templates select="ItemSentence/Column"/>
</p>
</xsl:template>
<xsl:template match="ItemSentence/Column">
<xsl:value-of select="Sentence"/>
</xsl:template>
</xsl:stylesheet>
結果がこちら(相変わらず環境によって見れなかったりするのでhtmlで)。
ついでなので同じXSLファイルで労働安全衛生法も変換。結果はこちら。
章、節だけの法令ならこれで問題なく変換できるのだが、編、章、節、款といった枝分かれがあったりなかったりする木構造になるとやや面倒になる。特に民法や労働安全衛生規則などがそうなのだが、それらについては次回にて。
平成31年2月12日労働安全衛生規則改正!気になるその内容は?
たまたま官報を見ていたら平成31年2月12日に労働安全衛生規則(以下「安衛則」)が改正されていました。よく読むと、林業関連の項目が結構変わったようです。列挙すると次の通り。
- 伐木作業における古い手法に関する規定の削除
- 伐木作業における安全対策の強化
- 材木運搬作業等の作業計画に「労働災害が発生した時の応急の措置及び傷病者の運搬の方法」の記載が義務化
本稿では主に1.と2.について取り上げたいと思います。
“平成31年2月12日労働安全衛生規則改正!気になるその内容は?” の続きを読む
