-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added TSV XSLT - Combined table separation into XSL
- Loading branch information
1 parent
7291127
commit 490212f
Showing
4 changed files
with
188 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<!-- Template for the root element --> | ||
<xsl:template match="/"> | ||
<xsl:variable name="type" select="'Pairs Table'"/> | ||
<xsl:variable name="header" select="$type"/> | ||
|
||
<xsl:call-template name="doctype"/> | ||
<html> | ||
<xsl:call-template name="html_head_template"> | ||
<xsl:with-param name="title" select="$header"/> | ||
</xsl:call-template> | ||
<xsl:call-template name="html_body_template"> | ||
<xsl:with-param name="header" select="$header"/> | ||
<xsl:with-param name="lines" select="//Line"/> | ||
</xsl:call-template> | ||
</html> | ||
</xsl:template> | ||
|
||
<!-- Template for creating the HTML body --> | ||
<xsl:template name="html_body_template"> | ||
<xsl:param name="header"/> | ||
<xsl:param name="lines"/> | ||
<body> | ||
<h1><xsl:value-of select="$header"/></h1> | ||
<hr/> | ||
<xsl:call-template name="table"> | ||
<xsl:with-param name="lines" select="$lines"/> | ||
</xsl:call-template> | ||
<hr/> | ||
</body> | ||
</xsl:template> | ||
|
||
<!-- Template for creating the table and underlying rows --> | ||
<xsl:template name="table"> | ||
<xsl:param name="lines"/> | ||
<table> | ||
<!-- Apply template to process header line --> | ||
<tr> | ||
<xsl:call-template name="processLine"> | ||
<xsl:with-param name="line" select="$lines[1]"/> | ||
<xsl:with-param name="isHeader" select="true()"/> | ||
</xsl:call-template> | ||
</tr> | ||
<!-- Apply templates to process non-header lines --> | ||
<xsl:apply-templates select="$lines[position() > 1]"/> | ||
</table> | ||
</xsl:template> | ||
|
||
<!-- Template to process each line --> | ||
<xsl:template match="Line"> | ||
<tr> | ||
<!-- Call template to process the line --> | ||
<xsl:call-template name="processLine"> | ||
<xsl:with-param name="line" select="."/> | ||
<xsl:with-param name="isHeader" select="false()"/> | ||
</xsl:call-template> | ||
</tr> | ||
</xsl:template> | ||
|
||
<!-- Template to split the contents of a line --> | ||
<xsl:template name="processLine"> | ||
<xsl:param name="line"/> | ||
<xsl:param name="isHeader"/> | ||
<!-- Split the line by the delimiter --> | ||
<xsl:call-template name="split"> | ||
<xsl:with-param name="string" select="$line"/> | ||
<xsl:with-param name="isHeader" select="$isHeader"/> | ||
</xsl:call-template> | ||
</xsl:template> | ||
|
||
<xsl:template name="split"> | ||
<xsl:param name="string" /> | ||
<xsl:param name="isHeader"/> | ||
<xsl:choose> | ||
<!-- If the string contains a delimiter character --> | ||
<xsl:when test="contains($string, $delimiter)"> | ||
<!-- Extract the value before the delimiter character --> | ||
<xsl:variable name="value" select="substring-before($string, $delimiter)" /> | ||
|
||
<!-- Process the extracted value --> | ||
<xsl:call-template name="process-value"> | ||
<xsl:with-param name="isHeader" select="$isHeader"/> | ||
<xsl:with-param name="value" select="$value" /> | ||
</xsl:call-template> | ||
|
||
<!-- Recursively call split template with the remaining string --> | ||
<xsl:variable name="remaining" select="substring-after($string, $delimiter)" /> | ||
<xsl:call-template name="split"> | ||
<xsl:with-param name="string" select="$remaining"/> | ||
<xsl:with-param name="isHeader" select="$isHeader"/> | ||
</xsl:call-template> | ||
</xsl:when> | ||
<!-- If no delimiter character is found --> | ||
<xsl:otherwise> | ||
<!-- Process the remaining part of the string --> | ||
<xsl:call-template name="process-value"> | ||
<xsl:with-param name="isHeader" select="$isHeader"/> | ||
<xsl:with-param name="value" select="$string" /> | ||
</xsl:call-template> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<!-- Should encapsulating quotes be removed from table cells? --> | ||
<xsl:variable name="removeQuotes" select="true()"/> | ||
|
||
<!-- What does an encapsulating quote look like? --> | ||
<xsl:variable name="quotes" select="'"'"/> | ||
|
||
<!-- Template to create table headers or table rows and remove encapsulating quotes --> | ||
<xsl:template name="process-value"> | ||
<xsl:param name="value"/> | ||
<xsl:param name="isHeader"/> | ||
|
||
<xsl:variable name="string"> | ||
<xsl:choose> | ||
<xsl:when test="$removeQuotes = true()"> | ||
<xsl:call-template name="removeQuotes"> | ||
<xsl:with-param name="string" select="$value"/> | ||
</xsl:call-template> | ||
</xsl:when> | ||
<xsl:when test="$removeQuotes = false()"> | ||
<xsl:value-of select="$value"/> | ||
</xsl:when> | ||
</xsl:choose> | ||
</xsl:variable> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$isHeader = true()"> | ||
<th><xsl:value-of select="$string"/></th> | ||
</xsl:when> | ||
<xsl:when test="$isHeader = false()"> | ||
<td><xsl:value-of select="$string"/></td> | ||
</xsl:when> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
<!-- Template to remove encapsulating quotes from a given string --> | ||
<xsl:template name="removeQuotes"> | ||
<xsl:param name="string"/> | ||
<xsl:variable name="startQuote" select="substring($string, 1, 1) = $quotes"/> | ||
<xsl:variable name="endQuote" select="substring($string, string-length($string), 1) = $quotes"/> | ||
<xsl:variable name="startRemoved"> | ||
<xsl:choose> | ||
<xsl:when test="$startQuote"> | ||
<xsl:value-of select="substring($string, 2)"/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="$string"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
<xsl:variable name="bothRemoved"> | ||
<xsl:choose> | ||
<xsl:when test="$endQuote"> | ||
<xsl:value-of select="substring($startRemoved, 1, string-length($startRemoved) - 1)"/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="$startRemoved"/> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
<xsl:value-of select="$bothRemoved"/> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<xsl:include href="extensions.xsl"/> | ||
<xsl:include href="tableextensions.xsl"/> | ||
<xsl:include href="separatedvaluestable.xsl"/> | ||
<xsl:output method="html" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes" media-type="text/html"/> | ||
|
||
<!-- TSV column delimiter --> | ||
<xsl:variable name="delimiter" select="'	'"/> | ||
|
||
</xsl:stylesheet> |