Skip to content

Instantly share code, notes, and snippets.

@martin-honnen
martin-honnen / cities.json
Last active July 16, 2023 08:07
sample XSLT 3.0 gist transforming JSON input to HTML output, doing some grouping
{
"cities": [
{
"city": {
"name": "Milano",
"pop": 5.23,
"country": "Italia",
"year": 1950
}
},
@martin-honnen
martin-honnen / module1.xsl
Created July 7, 2023 10:49
stylesheet module resolution test for GistResourceResolver
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:mode on-no-match="shallow-copy"/>
</xsl:stylesheet>
@martin-honnen
martin-honnen / main.py
Last active June 26, 2023 13:20
Use XSLT 3.0 and SaxonC HE to serialize child nodes of element node and wrap into CDATA section
from saxonche import *
with PySaxonProcessor(license=False) as saxon_proc:
xslt30_processor = saxon_proc.new_xslt30_processor()
xslt30_processor.transform_to_file(source_file='sample1.xml', stylesheet_file='serialize-wrap-in-cdata1.xsl', output_file='result-sample1.xml')
@martin-honnen
martin-honnen / README.md
Created June 26, 2023 11:54
Short, minimal demo sample to run XSLT 3 with Saxon to create several fo files from one XML input to then use a bat file to run Apache FOP on each fo file to create the corresponding PDF

Sample to create several .fo files with single XSLT 3.0 stylesheet and then run bat command to use FOP on each .fo file to create .pdf file.

Use e.g. Saxon 12 HE java -jar path-to-saxon-dir\saxon-he-12.2.jar -s:article-30-sample.xml -xsl:create-article-list-and-article-docs.xsl -o:article-list.fo to run the XSLT and create the various .fo files.

Then adapt the path in create-pdfs-from-fo-files.bat to point to your FOP installation and run the create-pdfs-from-fo-files.bat to create the PDFs.

@martin-honnen
martin-honnen / cities.xml
Created June 20, 2023 06:30
XSLT 3.0 grouping example: composite grouping key
<cities>
<city name="Milano" country="Italia" year="1950" pop="5.23"/>
<city name="Milano" country="Italia" year="1960" pop="5.29"/>
<city name="Padova" country="Italia" year="1950" pop="0.69"/>
<city name="Padova" country="Italia" year="1960" pop="0.93"/>
<city name="Paris" country="France" year="1951" pop="7.2"/>
<city name="Paris" country="France" year="1961" pop="7.6"/>
</cities>
@martin-honnen
martin-honnen / index.html
Created February 24, 2023 11:34
Sample minimal dart web app to use SaxonJS 2 to run XSLT 3 and insert transformation result in HTML document
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/dart-lang/sdk">
<title>quickstart</title>
<link rel="stylesheet" href="styles.css">
@martin-honnen
martin-honnen / feed-stylesheet-node-with-more-than-one-module-to-fn-transform.xq
Created May 17, 2022 12:42
What does fn:transform with a stylesheet-node parameter that is an XDM document node with more than one stylesheet element?
xquery version "3.1";
transform(map {
'stylesheet-node' : document { <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<xsl:next-match/>
<xsl:comment>Fragment 1</xsl:comment>
</xsl:template>
</xsl:stylesheet>,
@martin-honnen
martin-honnen / RunXSLT4.cs
Created October 8, 2021 09:29
Run "XSLT 4" with SaxonCS 11 EE from the command line as long as the transform interface of the original Saxon release is not up to it
using System;
using System.IO;
using Saxon.Api;
namespace SaxonCSRunXSLT4
{
class Program
{
static void Main(string[] args)
{
@martin-honnen
martin-honnen / SaxonXslt30TransformAppendToTextFile.java
Last active September 22, 2020 13:57
Use Saxon 9.9's Xslt30Transformer and setResultDocumentHandler to have xsl:result-document on any run append to existing files
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URI;
import java.util.function.Function;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.Destination;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
@martin-honnen
martin-honnen / accumulator-declaration2.xsl
Created November 3, 2017 11:49
Streamable XSLT 3 accumulator that counts col elements inside row element parent
<xsl:accumulator name="col-count" as="xs:integer" initial-value="0" streamable="yes">
<xsl:accumulator-rule match="row" select="0"/>
<xsl:accumulator-rule match="row/col" select="$value + 1"/>
</xsl:accumulator>