Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
- >
- <xsl:output method="html"/>
- <xsl:strip-space elements="*"/>
- <xsl:template match="/">
- <xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
- <html>
- <head><xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
- <!--<title>
- <xsl:value-of select="index/title"/>
- </title>-->
- <link rel="stylesheet" href="D:\Backup-Desktop\HKWB2014-Part A - Section 2 - Practice Directions-Deskrop\2500\main.css" type="text/css"/><xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
- </head>
- <body>
- <section class="tr_index">
- <xsl:apply-templates/>
- </section>
- </body>
- </html>
- </xsl:template>
- <xsl:template match="index">
- <div class="index">
- <xsl:variable name="num">
- <xsl:number level="any" format="01"/>
- </xsl:variable>
- <a name="CHA_IDX_{$num}" class="tr_toc_anchor"/>
- <div class="index-title">
- <!-- <xsl:apply-templates select="title"/>-->
- <xsl:value-of select="index/title/@text()"/>
- </div>
- <xsl:apply-templates select="indexdiv"/>
- </div>
- </xsl:template>
- <xsl:template match="indexdiv">
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template match="indexdiv/title">
- </xsl:template>
- <xsl:template match="indexentry">
- <div class="indexdiv">
- <div class="indexentry">
- <xsl:apply-templates/>
- </div>
- </div>
- </xsl:template>
- <xsl:template match="primaryie">
- <div class="primaryie">
- <xsl:apply-templates select="content-style"/>
- <xsl:if test="contains(current()/text(), '.')">
- <xsl:variable name="numberString" select="substring(current()/text(), string-length(substring-before(current()/text(),'.'))-1)"/>
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="$numberString"/>
- </xsl:call-template>
- </xsl:if>
- </div>
- </xsl:template>
- <xsl:template match="secondaryie">
- <div class="secondaryie">
- <xsl:apply-templates/>
- </div>
- </xsl:template>
- <xsl:template match="text()">
- <xsl:analyze-string select="." regex="[^,\s—[A-Z]+]+">
- <xsl:matching-substring>
- <xsl:variable name="range" select="tokenize(.,'—')"/>
- <xsl:variable name="pg" select="tokenize(.,'/')"/>
- <xsl:choose>
- <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',substring(.,1,1)))">
- <xsl:choose>
- <xsl:when test="contains($pg[3],'—')">
- <xsl:variable name="range-pg" as="item()*">
- <xsl:for-each select="$range">
- <xsl:sequence select="tokenize(.,'/')"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:for-each select="xs:integer($range-pg[3]) to xs:integer($range-pg[6])">
- <a href="er:#HKWBV1_ORD_{
- if (string(number($range-pg[1]))!='NaN') then
- format-number(number($range-pg[1]),'00')
- else
- $range-pg[1]}/P{string-join($range-pg[position()=(1,2)],'/')}/{.}">
- <xsl:value-of select="concat(string-join($range-pg[position()=(1,2)],'/'),'/',.)"/>
- </a>
- <xsl:text>, </xsl:text>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <a href="er:#HKWBV1_ORD_{
- if (string(number($pg[1]))!='NaN') then
- format-number(number($pg[1]),'00')
- else
- $pg[1]}/P{$pg[1]
- }/{string-join($pg[position()>1],'/')}">
- <xsl:value-of select="."/>
- </a>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="contains('PD',substring(.,1,2))">
- <a href="{concat('HKWBV1_SEC_',substring-after(substring-before(.,'/'),'PD'),'/PPD',translate(substring-after(.,'PD'),'.','-'))}">
- <xsl:value-of select="."/>
- </a>
- </xsl:when>
- <xsl:otherwise>
- <span class="invalid">
- <xsl:value-of select="."/>
- </span>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:matching-substring>
- <xsl:non-matching-substring>
- <xsl:value-of select="."/>
- </xsl:non-matching-substring>
- </xsl:analyze-string>
- </xsl:template>
- <xsl:template match="tertiaryie">
- <xsl:variable name="tertClassType">
- <xsl:value-of select="@level"/>
- </xsl:variable>
- <xsl:variable name="tertClassTypName">
- <xsl:value-of select="concat('tertiaryie-', $tertClassType)"/>
- </xsl:variable>
- <div class="tertiaryie">
- <xsl:apply-templates/>
- </div>
- </xsl:template>
- <xsl:template match="content-style" name="content-style">
- <xsl:variable name="fontStyle">
- <xsl:value-of select="concat('font-style-',@font-style)"/>
- </xsl:variable>
- <span class="{$fontStyle}">
- <xsl:variable name="textAll">
- <xsl:value-of select="text()"/>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="contains($textAll, '.')">
- <xsl:variable name="textOnly">
- <xsl:choose>
- <xsl:when test="contains($textAll,'.')">
- <xsl:value-of select="substring($textAll,1,string-length(substring-before($textAll,'.'))-1)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="text()"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="numbersOnly">
- <xsl:choose>
- <xsl:when test="contains($textAll,'.')">
- <xsl:value-of select="substring($textAll,string-length($textOnly))"/>
- </xsl:when>
- </xsl:choose>
- </xsl:variable>
- <xsl:value-of select="$textOnly"/>
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="$numbersOnly"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates/>
- </xsl:otherwise>
- </xsl:choose>
- </span>
- </xsl:template>
- <xsl:template name="numbersToLink">
- <xsl:param name="numbersString"/>
- <xsl:choose>
- <xsl:when test="contains($numbersString, '-')">
- <xsl:call-template name="splitByHyphen">
- <xsl:with-param name="numString" select="$numbersString"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="contains($numbersString, ' ')">
- <xsl:call-template name="Space">
- <xsl:with-param name="numString" select="$numbersString"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="contains($numbersString, ',')">
- <xsl:call-template name="splitByComma">
- <xsl:with-param name="numString" select="$numbersString"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="5 >= string-length(normalize-space($numbersString))">
- <xsl:variable name="x">
- <xsl:value-of select="substring-after($numbersString,'.')"/>
- </xsl:variable>
- <xsl:variable name="y">
- <xsl:value-of select="normalize-space(substring-before($numbersString,'.'))"/>
- </xsl:variable>
- <xsl:variable name="conca">
- <xsl:value-of select="concat('er:#CHA_CH_0',$y,'/P',$y,'-',$x)"/>
- </xsl:variable>
- <a href="{$conca}">
- <xsl:value-of select="$numbersString"/>
- </a>
- </xsl:when>
- <xsl:when test="6 >= string-length(normalize-space($numbersString))">
- <xsl:variable name="x">
- <xsl:value-of select="substring-after($numbersString,'.')"/>
- </xsl:variable>
- <xsl:variable name="y">
- <xsl:value-of select="normalize-space(substring-before($numbersString,'.'))"/>
- </xsl:variable>
- <xsl:variable name="conca">
- <xsl:value-of select="concat('er:#CHA_CH_0',$y,'/P',$y,'-',$x)"/>
- </xsl:variable>
- <a href="{$conca}">
- <xsl:value-of select="$numbersString"/>
- </a>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!--Space Template-->
- <xsl:template name="Space">
- <xsl:param name="numString"/>
- <xsl:choose>
- <xsl:when test="contains($numString,' ') and contains(substring-before($numString,' '),'.')">
- <xsl:variable name="StrLen">
- <xsl:value-of select="string-length(substring-before(substring-after($numString,'.'),' '))"/>
- </xsl:variable>
- <xsl:variable name="abc">
- <xsl:value-of select="normalize-space(substring-before($numString,'.'))"/>
- </xsl:variable>
- <xsl:variable name="def">
- <xsl:choose>
- <xsl:when test="contains($numString,',')">
- <xsl:value-of select="translate(substring-before(substring-after($numString,'.'),' '),',','' )"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="substring-before(substring-after($numString,'.'),' ') "/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="conct">
- <xsl:choose>
- <xsl:when test="$StrLen <= 2">
- <xsl:value-of select="concat('er:#CHA_CH_0',$abc,'/P',$abc,'-00',$def)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="concat('er:#CHA_CH_0',$abc,'/P',$abc,'-',$def)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="Con1">
- <xsl:value-of select="concat($abc,'.00',$def)"/>
- </xsl:variable>
- <xsl:variable name="Con">
- <xsl:value-of select="concat($abc,'.',$def)"/>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$StrLen <= 2">
- <a href="{$conct}">
- <xsl:value-of select="$Con1"/>
- </a>
- </xsl:when>
- <xsl:otherwise>
- <a href="{$conct}">
- <xsl:value-of select="$Con"/>
- </a>
- </xsl:otherwise>
- </xsl:choose>
- <!--<a href="{$conct}">
- <xsl:value-of select="$Con"/>
- </a>-->
- <xsl:choose>
- <xsl:when test="contains(.,', ')">
- <xsl:text>, </xsl:text>
- </xsl:when>
- <xsl:when test="contains(.,'-')">
- <xsl:text>– </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text> </xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="normalize-space(substring-after($numString,' '))"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="normalize-space(substring-after($numString,' '))"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="splitByComma">
- <xsl:param name="numString"/>
- <xsl:choose>
- <xsl:when test="contains(substring-before($numString,','), '-')">
- <xsl:call-template name="splitByHyphen">
- <xsl:with-param name="numString" select="$numString"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="contains($numString,',')">
- <xsl:variable name="abc">
- <xsl:value-of select="normalize-space(substring-before($numString,'.'))"/>
- </xsl:variable>
- <xsl:variable name="def">
- <xsl:value-of select="substring-before(substring-after($numString,'.'),',') "/>
- </xsl:variable>
- <xsl:variable name="conct">
- <xsl:value-of select="concat('er:#CHA_CH_0',$abc,'/P',$abc,'-',$def)"/>
- </xsl:variable>
- <a href="{$conct}">
- <xsl:value-of select="substring-before($numString,',')"/>
- </a>
- <xsl:text>, </xsl:text>
- <xsl:if test="contains(substring-after($numString,','), '.')">
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="normalize-space(substring-after($numString,','))"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:when>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="splitByHyphen">
- <xsl:param name="numString"/>
- <xsl:choose>
- <xsl:when test="contains($numString,'-')">
- <xsl:variable name="abc">
- <xsl:value-of select="normalize-space(substring-before($numString,'.'))"/>
- </xsl:variable>
- <xsl:variable name="def">
- <xsl:value-of select="substring-before(substring-after($numString,'.'),'-') "/>
- </xsl:variable>
- <xsl:variable name="conct">
- <xsl:value-of select="concat('er:#CHA_CH_0',$abc,'/P',$abc,'-',$def)"/>
- </xsl:variable>
- <a href="{$conct}">
- <xsl:value-of select="substring-before($numString,'-')"/>
- </a>
- <xsl:text>–</xsl:text>
- <xsl:if test="contains(substring-after($numString,'-'), '.')">
- <xsl:call-template name="numbersToLink">
- <xsl:with-param name="numbersString" select="normalize-space(substring-after($numString,'-'))"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:when>
- </xsl:choose>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment