Skip to content

Instantly share code, notes, and snippets.

View eerohele's full-sized avatar
🐺

Eero Helenius eerohele

🐺
View GitHub Profile
@eerohele
eerohele / build.gradle.kts
Last active June 5, 2018 10:59
A Gradle Script Kotlin buildscript for building Saxon-HE (http://saxonica.com)
// README:
//
// Save this file and settings.gradle into a directory. Then:
//
// $ gradle
// $ gradle jar
// $ java -cp build/libs/saxon9he.jar net.sf.saxon.Transform <options>
import org.gradle.api.tasks.Copy
@eerohele
eerohele / xslt.clj
Last active October 15, 2020 05:26
Write XSLT with Clojure
(ns clj-xslt
(:require [clojure.data.xml :as xml])
(:import (java.time LocalDateTime)
(java.time.format DateTimeFormatter)
(java.io StringBufferInputStream StringWriter StringReader)
(javax.xml.transform.stream StreamSource)
(net.sf.saxon.s9api XsltCompiler Processor)
(net.sf.saxon Configuration)))
(def processor
@eerohele
eerohele / pain.clj
Last active April 14, 2017 19:31
Example of a Clojure Schematron implementation
(ns ^:no-doc clojutron.examples.pain-mdr
(:require [clojure.java.io :as io]
[clojure.data.zip.xml :refer [xml1-> attr text]]
[clojutron.schema :refer :all]
[clojure.edn :as edn])
(:refer-clojure :exclude [assert])
(:import (org.iban4j BicUtil IbanUtil)))
(def iso4217-currency-codes
"Read the set of valid ISO 4217 currency codes from an EDN file."
@eerohele
eerohele / pain03-to-html.css
Last active May 22, 2017 14:13
Create a HTML representation of a Payments Initiation message (pain.001.001.03)
:root {
--baseline: 1.5rem;
--background-color: #090415;
--text-color-default: #F9EEF9;
--text-color-code: #F9EEF9;
--color-emphasis-dark: #1B0C40;
--font-sans-serif: "Fira Sans", Helvetica, sans-serif;
--font-monospace: "Fira Mono", monospace;
}
@eerohele
eerohele / Script.fsx
Last active March 20, 2017 09:16
F# Schematron
let namespaces =
Some [("p", "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03")]
let pain03 =
schema namespaces [
pattern "Group header" [
rule "p:Document/p:CstmrCdtTrfInitn" [
assert' "<NbOfTxs> is equal to the number of individual transactions contained in the message."
"xs:integer(p:GrpHdr/p:NbOfTxs) eq xs:integer(count(p:PmtInf/p:CdtTrfTxInf))"
@eerohele
eerohele / XSLT.ps1
Last active April 26, 2017 07:02
Run an XSLT transformation on a glob of files with PowerShell and XslCompiledTransform
Param(
[Parameter(Mandatory = $True)] [string] $Path,
[Parameter(Mandatory = $True)] [string] $Xsl,
[Parameter(Mandatory = $False)] [string] $Filter = "*.xml",
[Parameter(Mandatory = $False)] [string] $Target = (Join-Path (Convert-Path .) "target"),
[Parameter(Mandatory = $False)] [hashtable] $Params
)
Set-StrictMode -version 2.0
@eerohele
eerohele / Sample.fs
Created October 8, 2016 15:43
Unit testing XSLT with F#
open XSLTUnit
[<TestFixture>]
type ``Testing XSLT with F#``() =
inherit XSLTUnit(Uri(@"C:\TEMP\test.xsl"))
[<Test>]
member xsl.``Applying a template with a tunnel template parameter in the default mode``() =
xsl.Apply("""<input attribute="1"/>""", parameters = parameters Template true [(QName("number"), 42)])
|> should produce """<output attribute="42"/>"""
@eerohele
eerohele / Html5TableSpecification.scala
Last active August 26, 2016 05:42
Using Expek to unit test DITA-OT HTML5 table transformations
import org.specs2._
import com.github.eerohele.expek.XsltSpecification
import net.sf.saxon.s9api.XdmNode
import scala.xml.{Elem, Node, XML}
class Html5TableSpecification extends mutable.Specification with XsltSpecification {
import com.github.eerohele.expek.NodeConversions._
class MySpecification extends XsltSpecification(new File("src/test/resources/stylesheets/test.xsl")) {
"Simple transformation" >> {
applying(<paragraph>foo</paragraph>) yields(<p>foo</p>)
}
"Set mode and parameters" >> {
applying(<paragraph>foo</paragraph>)
.withMode("main")
.withParameters(tunnel = false)("foo" -> "bar", "baz" -> "quux")
.yields(<p>bar, quux</p>)
@eerohele
eerohele / saxon-b-debug.txt
Created June 2, 2016 07:45
Ant debug logs
This file has been truncated, but you can view the full file.
Adding reference: ant.PropertyHelper
Detected Java version: 1.8 in: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre
Detected OS: Mac OS X
Adding reference: ant.ComponentHelper
Setting ro project property: dita.output.dir -> /tmp/out
Setting ro project property: args.input -> /Users/eerohele/Public/dita-test/dita-1.2-specification/dita-1.2-specification.ditamap
Setting ro project property: transtype -> html5
Setting ro project property: ant.file -> /Users/eerohele/Git/dita-ot/src/main/build.xml
Setting ro project property: ant.file.type -> file
Adding reference: ant.projectHelper