Xsl

From Gramps
Revision as of 01:21, 31 May 2012 by Romjerome (Talk | contribs)

Jump to: navigation, search


Definition

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. We 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.

Examples

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

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/"              
exclude-result-prefixes="gr">
<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">
<g>
<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>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:stylesheet>
  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

Also, you should have a look to Geography.