Skip to content

Commit afb49f1

Browse files
committed
[tutorial] Add local view note
1 parent 0b11b2f commit afb49f1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

doc/tutorial.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,46 @@ format option when loading the document:
888888
Advanced odML-Features
889889
======================
890890

891+
View odML documents in a web browser
892+
------------------------------------
893+
894+
By default all odML files are saved in the XML format without the capability to view
895+
the plain files in a browser. By default you can use the command line tool ``odmlview``
896+
to view saved odML files locally. Since this requires the start of a local server,
897+
there is another option to view odML XML files in a web browser.
898+
899+
You can use an additional feature of the ``odml.tools.XMLWriter`` to save an odML
900+
document with an embedded default stylesheet for local viewing:
901+
902+
>>> import odml
903+
>>> from odml.tools import XMLWriter
904+
>>> doc = odml.Document() # minimal example document
905+
>>> filename = "viewable_document.xml"
906+
>>> XMLWriter(doc).write_file(filename, local_style=True)
907+
908+
Now you can open the resulting file 'viewable_document.xml' in any current web-browser
909+
and it will render the content of the odML file.
910+
911+
If you want to use a custom style sheet to render an odML document instead of the default
912+
one, you can provide it as a string to the XML writer. Please note, that it cannot be a
913+
full XSL stylesheet, the outermost tag of the XSL code has to be
914+
``<xsl:template match="odML"> [your custom style here] </xsl:template>``:
915+
916+
>>> import odml
917+
>>> from odml.tools import XMLWriter
918+
>>> doc = odml.Document() # minimal example document
919+
>>> filename = "viewable_document.xml"
920+
>>> own_template = """<xsl:template match="odML"> [your custom style here] </xsl:template>"""
921+
>>> XMLWriter(doc).write_file(filename, custom_template=own_template)
922+
923+
Please note that if the file is saved using the '.odml' extension and you are using
924+
Chrome, you will need to map the '.odml' extension to the browsers Mime-type database as
925+
'application/xml'.
926+
927+
Also note that any style that is saved with an odML document will be lost, when this
928+
document is loaded again and changes to the content are added. In this case the required
929+
style needs to be specified again when saving the changed file as described above.
930+
891931
Advanced knowledge on Values
892932
----------------------------
893933

0 commit comments

Comments
 (0)