= XSLT = [[TOC]] XSLT and XPath are two key technologies used within Sahana Eden to allow easy importing and exporting of information in a wide variety of formats. Support for importing and exporting data is mostly managed via XSLT templates, which can even be done [wiki:S3XRC/S3XML/Transformation on-the-fly]. == Sahana Data Models == The underlying data models in {{{models/}}} and {{{modules/s3db/}}} define the resulting structure that will be within the XML. == Sahana XML Representation == See: [wiki:S3/S3XML] There are 2 parameters which are passed in: * name (comes from the resourcename - e.g. 'shelter') * xsltmode (passed in as a var on the URL - e.g. '&xsltmode=extended') A collection of useful reusable functions are stored in {{{static/formats/xml/commons.xsl}}} == Exporting Data from Sahana == Sahana export templates are stored in: {{{static/formats/*/export.xsl}}} == Importing Data from Sahana == Sahana import templates are stored in: {{{static/formats/*/import.xsl}}} == Background Info and Resources == Sahana XSLT/XPath capability is provided by [http://lxml.de/ lxml]. Currently lxml only supports XSLT/XPath 1.0. * [http://www.w3schools.com/xsl/default.asp XSLT Tutorial] on w3schools * [http://www.w3schools.com/xpath/default.asp XPath Tutorial] on w3schools * [http://www.dpawson.co.uk/xsl/sect1/sect1.html XSLT starter resources] by Dave Pawson * [http://www.dpawson.co.uk/xsl/sect2/sect21.html XSLT FAQ] by Dave Pawson * [http://www.w3.org/TR/2007/REC-xslt20-20070123/ XSLT V2 reference] on W3C * [http://www.w3.org/TR/2007/REC-xpath20-20070123/ XPath V2 reference] on W3C * [http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog interactive xslt environment] == Debugging == Basic stylesheet checking can be done outside Sahana using the same functions as-used internally: * {{{static/scripts/tools/xsltransform.py}}} * {{{static/scripts/tools/csv2xml.py}}} {{{ cd eden python static/scripts/tools/csv2xml.py private/templates/default/certificate.csv static/formats/s3csv/hrm/certificate.xsl }}} Full debugging can be done using [http://xalan.apache.org/xalan-j/ Xalan]. Start by converting smaller extracts in debug mode: {{{ python static/scripts/tools/csv2xml.py private/templates/default/certificate.csv > certificate.xml java -jar xalan.jar -param name certificate -tt -tg -ts -in certificate.xml -xsl static/formats/s3csv/hrm/certificate.xsl }}} or {{{ java -jar xalan.jar -param name shelter -param xsltmode extended -tt -tg -ts -in japanquake2011_shelter_extract.kml -xsl web2py\applications\eden\static\formats\kml\import.xsl -out shelters.xml }}} Then process the full thing in non-debug mode: {{{ java -jar xalan.jar -param name shelter -param xsltmode extended -in japanquake2011_shelter.kml -xsl web2py\applications\eden\static\formats\kml\import.xsl -out shelters.xml }}} For a graphical IDE (Java, so cross-platform), you can trial [http://editix.com EditX] == See Also == * DeveloperGuidelines * [wiki:S3/S3XML/Transformation S3/S3XML/Transformation]