marge node using attributes value in xslt



I have an xslt which makes multiple and using attributes values.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:xs="http://ift.tt/tphNwY" exclude-result-prefixes="xs"
version="2.0">
<xsl:strip-space elements="*"/>

<xsl:template match="/Document">
<xsl:element name="html">
<xsl:element name="head">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<xsl:element name="title">Document</xsl:element>
</xsl:element>
<xsl:element name="body">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="page">
<div class="pages" id="{@pageseq}">
<xsl:apply-templates/>
</div>
</xsl:template>

<xsl:template match="block">
<xsl:choose>
<xsl:when test="child::row">
<table cellpadding="0" cellspacing="0" width="100%" border="1">
<xsl:apply-templates/>
</table>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:apply-templates/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="formatting">
<xsl:choose>
<xsl:when test="@bold and @italic and @smallcap">
<xsl:element name="b">
<xsl:element name="i">
<xsl:element name="small">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="@bold and @italic">
<xsl:element name="b">
<xsl:element name="i">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="@bold and @smallcap">
<xsl:element name="b">
<xsl:element name="small">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="@italic and @smallcap">
<xsl:element name="i">
<xsl:element name="small">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="@bold">
<xsl:element name="b">
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="@italic">
<xsl:element name="i">
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="@smallcap">
<xsl:element name="small">
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="word"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="word">
<xsl:choose>
<xsl:when test="@superscript">
<xsl:variable name="superscript" select="@superscript"/>
<xsl:choose>
<xsl:when test="@superscript = '0'">
<xsl:variable name="data" select="substring(.,1,1)"/>
<sup>
<xsl:value-of select="$data"/>
</sup>
<xsl:value-of select="concat(substring-after(.,$data),' ')"/>
</xsl:when>
<xsl:when test="contains(@superscript,',')">
<xsl:variable name="start">
<xsl:value-of select="substring-before(@superscript,',')"/>
</xsl:variable>
<xsl:variable name="end">
<xsl:value-of select="string-length(.)"/>
</xsl:variable>
<xsl:value-of
select="substring-before(.,substring(.,$start + 1,$end))"/>
<sup>
<xsl:value-of select="substring(.,$start + 1,$end)"/>
</sup>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="sup" select="@superscript"/>
<xsl:variable name="data" select="substring(.,$sup+1,1)"/>
<xsl:value-of select="substring-before(.,$data)"/>
<sup>
<xsl:value-of select="$data"/>
</sup>
<xsl:value-of select="concat(substring-after(.,$data),' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@subscript">
<xsl:variable name="subscript" select="@subscript"/>
<xsl:choose>
<xsl:when test="@subscript = '0'">
<xsl:variable name="data" select="substring(.,1,1)"/>
<sup>
<xsl:value-of select="$data"/>
</sup>
<xsl:value-of select="concat(substring-after(.,$data),' ')"/>
</xsl:when>
<xsl:when test="contains(@subscript,',')">
<xsl:variable name="start">
<xsl:value-of select="substring-before(@subscript,',')"/>
</xsl:variable>
<xsl:variable name="end">
<xsl:value-of select="string-length(.)"/>
</xsl:variable>
<xsl:value-of
select="substring-before(.,substring(.,$start + 1,$end))"/>
<sub>
<xsl:value-of select="substring(.,$start + 1,$end)"/>
</sub>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="sub" select="@subscript"/>
<xsl:variable name="data" select="substring(.,$sub+1,1)"/>
<xsl:value-of select="substring-before(.,$data)"/>
<sub>
<xsl:value-of select="$data"/>
</sub>
<xsl:value-of select="concat(substring-after(.,$data),' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Table -->
<xsl:template match="row">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>

<xsl:template match="cell">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>

</xsl:stylesheet>


For input please visit:- http://ift.tt/1tekZ2q or http://ift.tt/1tekZ2w


No comments:

Post a Comment