Difference between revisions of "Xsl"

From Gramps
Jump to: navigation, search
(Examples)
(Examples)
Line 56: Line 56:
  
 
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
 
  <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.1.4/"               
+
  xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd" xmlns:gr="http://gramps-project.org/xml/1.2.0/"               
 
  exclude-result-prefixes="gr">
 
  exclude-result-prefixes="gr">
 
  <xsl:output method="xml" indent="yes" media-type="image/svg"/>
 
  <xsl:output method="xml" indent="yes" media-type="image/svg"/>
Line 79: Line 79:
 
  xsltproc --novalid xxx.xsl data.xml > map.svg
 
  xsltproc --novalid xxx.xsl data.xml > map.svg
 
You will get a layer according to specified dimensions on XSLT stylesheet.
 
You will get a layer according to specified dimensions on XSLT stylesheet.
 +
 +
Ex: [http://romjerome.ifrance.com/carte.png carte.png] uses a custom [http://en.wikipedia.org/wiki/Coordinate_system#Geographical_systems frame of reference]
 +
<rect x="{(($long+(-4))*16)*120}" y="{(1000-$lat*20)*40}" width="5px" height="5px"/>
 +
<text x="{(($long+(-4))*16)*116}" y="{(1000-$lat*20)*40}" font-size="13px"><xsl:value-of select="ptitle"/>
 +
for displaying what we want, not always practical but fast and effective.

Revision as of 05:09, 23 July 2008


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. 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
  • a bridge between two open programs (GRAMPS <-> Tellico)

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.

  • 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="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.

Ex: carte.png uses a custom frame of reference

<rect x="{(($long+(-4))*16)*120}" y="{(1000-$lat*20)*40}" width="5px" height="5px"/>
<text x="{(($long+(-4))*16)*116}" y="{(1000-$lat*20)*40}" font-size="13px"><xsl:value-of select="ptitle"/>

for displaying what we want, not always practical but fast and effective.