From Gramps
Jump to: navigation, search

XSL is a family of transformation languages which allows us to describe how files encoded in the XML standard are to be formatted or transformed.

There are three languages in the family:

  • XSLT (eXtensible Stylesheet Language Transformation)
  • XPath (an expression language for addressing portions)
  • XSL-FO (eXtensible Stylesheet Language - Formatting Objects)

How using XSL ?

We may transform, format every XML with a XML/XSL parser. There is many parsers. The most accessible could be: xsltproc.

With simple command-line like:

xsltproc xx.xsl xx.xml > new.xml

you may generate a new file without loosing data.

Also, you may modify basic.py from python-xslt package.

How this work ?

There is many tutorials on the Web. XSL allows test, variable, param, function and uses templates.

You can work with DOM or not. That also depending on the memory available.

We don't really iterate through the file, it is recursive. We retrieve data with XPath.

Using XSL with Gramps XML

Some people use perl or python for retrieving some data from GEDCOM.

You may use XSL for this on Gramps XML, see XPaths.

Gramps XML is documented and coherent, we may use it for :

  • a database resume (output : HTML, XML, PS, PDF or SVG).
  • filtering some data and transforming result (Ancestors.xsl, Birthday.xsl ).
  • a bridge between two open programs (Gramps <-> Tellico).
  • a web form.


  • If you select Gramps object on XSL, and use this code with HTML output :
   <xsl:attribute name="src">
    <xsl:value-of select="@src"/>

then you will be able to display media objects on a HTML file. You may use all HTML codes or .css file for having what you want. Sample on a 2472 bug-report.

  • With XML, you will be able to make SVG. To generate a basic ancestors geographical map area with Gramps coordinates.

For France area (dirty and quick test) :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd" xmlns:gr="http://gramps-project.org/xml/1.2.0/"              
<xsl:output method="xml" indent="yes" media-type="image/svg"/>
<xsl:template match="/">
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" 
width="2000px" height="1000px" id="svg2">
<xsl:for-each select="gr:database/gr:places/gr:placeobj">
<xsl:variable name="long" select="gr:coord/@long"/>
<xsl:variable name="lat" select="gr:coord/@lat"/>
<xsl:variable name="title" select="gr:ptitle"/>
<rect x="{($long)*300}" y="{(1000-$lat*20)*20}" width="5px" height="5px"/>
<text x="{($long)*300}" y="{(1000-$lat*20)*20}" font-size="8px"><xsl:value-of select="gr:ptitle"/></text>
  1. gunzip a copy of your data.gramps.
  2. try:
xsltproc --novalid xxx.xsl data.xml > map.svg

You will get a layer according to specified dimensions on XSLT stylesheet.

It uses a custom frame of reference for displaying all places in France, not always practical but fast and effective.

Areas on East France

See also