Difference between revisions of "Xsl"

From Gramps
Jump to: navigation, search
(Examples)
m (cleanup)
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Developers/General]]
 
 
==Definition==
 
 
 
[http://www.w3.org/Style/XSL/ 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.
 
[http://www.w3.org/Style/XSL/ 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.
  
Line 31: Line 27:
 
We don't really iterate through the file, it is recursive. We retrieve data with XPath.
 
We don't really iterate through the file, it is recursive. We retrieve data with XPath.
  
==Using XSL with gramps XML==
+
==Using XSL with Gramps XML==
  
 
Some people use perl or python for retrieving some data from GEDCOM.
 
Some people use perl or python for retrieving some data from GEDCOM.
We may use XSL for this on GRAMPS XML.
 
GRAMPS XML is [http://gramps-project.org/xml/1.2.0/ documented] and coherent, we may use it for :
 
  
* a database resume (output : HTML, XML, PS, PDF or SVG)
+
You may use XSL for this on Gramps XML, see [[media:Xpaths.gz|XPaths]].
* filtering some data and transforming result  
+
 
* a bridge between two open programs (GRAMPS <-> [[tellico|Tellico]])
+
Gramps XML is [http://gramps-project.org/xml/1.4.0/ documented] and coherent, we may use it for :
 +
 
 +
* a database resume (output : HTML, XML, PS, PDF or SVG).
 +
* filtering some data and transforming result ([[media:Ancestors.xsl.gz|Ancestors.xsl]],  [[media:Birthday.xsl.gz|Birthday.xsl]] ).
 +
* a bridge between two open programs (Gramps <-> [[tellico|Tellico]]).
 +
* a web form.
  
 
==Examples==
 
==Examples==
  
* If you select GRAMPS object on XSL, and use this code with HTML output :
+
* If you select Gramps object on XSL, and use this code with HTML output :
 
   <img>
 
   <img>
 
     <xsl:attribute name="src">
 
     <xsl:attribute name="src">
Line 50: Line 49:
 
   </img>
 
   </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.
+
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 {{bug|2472}} bug-report.
  
* With XML, you will be able to make SVG. To generate a basic ancestors geographical map area with gramps coordinates.  
+
* 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) :
+
For [[France]] area (dirty and quick test) :
  
 
  <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"  
Line 66: Line 66:
 
  <xsl:variable name="long" select="gr:coord/@long"/>
 
  <xsl:variable name="long" select="gr:coord/@long"/>
 
  <xsl:variable name="lat" select="gr:coord/@lat"/>
 
  <xsl:variable name="lat" select="gr:coord/@lat"/>
  <xsl:variable name="title" select="ptitle"/>
+
  <xsl:variable name="title" select="gr:ptitle"/>
 
  <rect x="{($long)*300}" y="{(1000-$lat*20)*20}" width="5px" height="5px"/>
 
  <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>
 
  <text x="{($long)*300}" y="{(1000-$lat*20)*20}" font-size="8px"><xsl:value-of select="gr:ptitle"/></text>
Line 80: Line 80:
 
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]
+
It uses a custom [http://en.wikipedia.org/wiki/Coordinate_system#Geographical_systems frame of reference] for displaying all places in France, not always practical but fast and effective.
<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"/>
+
[[File:Fr_coordonnées_positives.png|300px|thumb|center|Areas on East France]]
for displaying what we want, not always practical but fast and effective.
+
 
 +
==See also==
 +
* [[Geography]]
 +
 
 +
[[Category:Developers/General]]

Revision as of 01:11, 12 February 2013

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.

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

See also