Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
#365 - using Saxon for xsl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g4s8 committed Jul 7, 2018
1 parent b8e7648 commit eaef58e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
25 changes: 17 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ task :xsd, [:version] do |_, args|
path = p.gsub(%r{^xml/}, 'upgrades/').gsub(%r{/[^/]+$}, '/*.xsl')
current = Gem::Version.new(args[:version])
Dir[path].each do |x|
if Gem::Version.new(File.basename(x).gsub(/-.+$/, '')) <= current
xml = Nokogiri::XSLT(File.read(x)).transform(xml)
end
next unless Gem::Version.new(
File.basename(x).gsub(/-.+$/, '')
) <= current
tmp = Dir::Tmpname.make_tmpname(['/tmp/x', '.xml'], nil)
File.write(tmp, xml)
xml = Nokogiri::XML(xsl_transform(tmp, x))
File.delete(tmp)
end
end
if File.basename(p).start_with?('-')
Expand Down Expand Up @@ -162,8 +166,10 @@ desc 'Run XSL tests'
task :xsltest do
puts 'Running XSL tests...'
Dir['xsl-test/**/*.xsl'].each do |p|
xsl = Nokogiri::XSLT(File.open(p))
xsl.transform(Nokogiri::XML('<empty/>'))
tmp = Dir::Tmpname.make_tmpname(['/tmp/empty', '.xml'], nil)
File.write(tmp, Nokogiri::XML('<empty/>'))
puts xsl_transform(tmp, p)
File.delete(tmp)
end
puts "\nAll XSL tests passed\n\n"
end
Expand Down Expand Up @@ -242,7 +248,6 @@ task :site, [:version] do |_, args|
File.write(f, File.read(f).gsub(/SNAPSHOT/, args[:version]))
end
puts "Version #{args[:version]} injected into all site files"
xslt = Nokogiri::XSLT(File.read('misc/index-html.xsl'))
Dir['target/site/**/*'].reject { |d| File.file?(d) }.each do |d|
xml = Nokogiri::XML::Builder.new do |x|
path = d.gsub('target/site', '')
Expand All @@ -264,8 +269,12 @@ task :site, [:version] do |_, args|
end
end
end.doc
File.write(File.join(d, 'index.xml'), xml.to_s)
File.write(File.join(d, 'index.html'), xslt.transform(xml))
index = File.join(d, 'index.xml')
File.write(index, xml.to_s)
File.write(
File.join(d, 'index.html'),
Nokogiri::XML(xsl_transform(index, 'misc/index-html.xsl'))
)
end
puts 'Index files created'
puts "The site is ready in target/site\n\n"
Expand Down
25 changes: 13 additions & 12 deletions xsl/templates.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ SOFTWARE.
<xsl:variable name="day" select="number(substring($iso, 9, 2))"/>
<xsl:variable name="hour" select="number(substring($iso, 12, 2))"/>
<xsl:variable name="minute" select="number(substring($iso, 15, 2))"/>
<xsl:variable name="monthdays" select="28"/>
<xsl:choose>
<xsl:when test="$month = 1 or $month = 3 or $month = 5 or $month = 7 or $month = 8 or $month = 10 or $month = 12">
<xsl:variable name="monthdays" select="31"/>
</xsl:when>
<xsl:when test="$month = 4 or $month = 6 or $month = 9 or $month = 11">
<xsl:variable name="monthdays" select="30"/>
</xsl:when>
<xsl:when test="$month = 2 and ($year mod 4 = 0 and $year mod 100 != 0) or $year mod 400">
<xsl:variable name="monthdays" select="29"/>
</xsl:when>
</xsl:choose>
<xsl:variable name="monthdays">
<xsl:choose>
<xsl:when test="$month = 1 or $month = 3 or $month = 5 or $month = 7 or $month = 8 or $month = 10 or $month = 12">
<xsl:value-of select="31"/>
</xsl:when>
<xsl:when test="$month = 4 or $month = 6 or $month = 9 or $month = 11">
<xsl:value-of select="30"/>
</xsl:when>
<xsl:when test="$month = 2 and ($year mod 4 = 0 and $year mod 100 != 0) or $year mod 400">
<xsl:value-of select="29"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$minute + $hour * 60 + $day * 60 * 24 + $month * 60 * 24 * $monthdays + $year * 60 * 24 * 365"/>
</xsl:template>
<xsl:template name="date">
Expand Down

0 comments on commit eaef58e

Please sign in to comment.