Skip to content

Commit 2c79fb6

Browse files
authored
Merge pull request #347 from mpsonntag/localstyle
Add inline style option when saving XML documents LGTM
2 parents b748339 + afb49f1 commit 2c79fb6

File tree

4 files changed

+189
-9
lines changed

4 files changed

+189
-9
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

docs/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ The Python installation features multiple convenience commandline scripts.
7979

8080
- `odmlconvert`: Converts odML files of previous file versions into the current one.
8181
- `odmltordf`: Converts odML files to the supported RDF version of odML.
82-
- `odmlview`: Render and browse local XML odML files in the webbrowser.
82+
- `odmlview`: Render and browse local XML odML files without stylesheet in the webbrowser.
8383

8484
All scripts provide detailed usage descriptions by adding the `help` flag to the command.
8585

8686
odmlconvert -h
8787
odmltordf -h
8888
odmlview -h
8989

90+
### Browsing odML files
91+
92+
odML XML files can be saved with an included XSL stylesheet for convenient local
93+
viewing via a web browser. To use this option, save odML documents using the `XMLWriter`
94+
instead of `odml.save()`:
95+
96+
XMLWriter(doc).write_file("filename.xml", local_style=True)
97+
9098
### odML - NIX conversion script
9199

92100
You can also find a command line script for importing metadata from odML files into the

0 commit comments

Comments
 (0)