1 | XSLT section |
---|
2 | ============ |
---|
3 | |
---|
4 | A XSLT pipeline section lets you apply stylesheet to some XML data stored on |
---|
5 | item. The XSLT section blueprint name is ``quintagroup.transmogrifier.xslt``. |
---|
6 | |
---|
7 | That data need to be transformed is determined by ``source`` option. It gives |
---|
8 | the key in dictionay where data is stored. Dictionary is standard structure |
---|
9 | for storing files data in other our sections. Data is stored in item on ``_files`` |
---|
10 | key, but this can be changed with ``files-key`` option. |
---|
11 | |
---|
12 | Usually stylesheets are used to transform data returned by ``marshall`` section. |
---|
13 | We register those stylesheets in ZCML with special directive, for example: |
---|
14 | |
---|
15 | :: |
---|
16 | |
---|
17 | <stylesheet xmlns="http://namespaces.zope.org/transmogrifier" |
---|
18 | from="OldPortalType" |
---|
19 | to="NewPortalType" |
---|
20 | source="marshall" |
---|
21 | file="path/to/stylesheet.xsl" |
---|
22 | /> |
---|
23 | |
---|
24 | ``source`` attribute in this directive is similar to that in section option. |
---|
25 | The default value for this option is ``marshall``. |
---|
26 | |
---|
27 | Which stylesheet to use is determined for every pipeline item by inspecting |
---|
28 | it's values stored on keys specified in ``from-key`` and ``to-key`` section |
---|
29 | options. These options are similar to ``from`` and ``to`` attributes in |
---|
30 | ZCML directive. If item hasn't those keys, it will be skipped. |
---|
31 | |
---|
32 | >>> import tempfile |
---|
33 | >>> tmp = tempfile.NamedTemporaryFile('w+', suffix='.xsl') |
---|
34 | >>> tmp.flush() |
---|
35 | >>> stylesheet_registry.registerStylesheet('marshall', 'Blog', 'Weblog', tmp.name) |
---|
36 | >>> xslt = """ |
---|
37 | ... [transmogrifier] |
---|
38 | ... pipeline = |
---|
39 | ... xsltsource |
---|
40 | ... xslt |
---|
41 | ... printer |
---|
42 | ... |
---|
43 | ... [xsltsource] |
---|
44 | ... blueprint = quintagroup.transmogrifier.tests.xsltsource |
---|
45 | ... |
---|
46 | ... [xslt] |
---|
47 | ... blueprint = quintagroup.transmogrifier.xslt |
---|
48 | ... source = marshall |
---|
49 | ... from-key = _old_type |
---|
50 | ... to-key = _type |
---|
51 | ... |
---|
52 | ... [printer] |
---|
53 | ... blueprint = collective.transmogrifier.sections.tests.pprinter |
---|
54 | ... """ |
---|
55 | >>> registerConfig(u'quintagroup.transmogrifier.tests.xslt', xslt) |
---|
56 | >>> transmogrifier(u'quintagroup.transmogrifier.tests.xslt') # doctest: +ELLIPSIS, +REPORT_NDIFF |
---|
57 | {} |
---|
58 | {'_type': 'Weblog'} |
---|
59 | {'_old_type': 'Blog'} |
---|
60 | {'_files': {'manifest': {'data': 'xml', 'name': 'manifest.xml'}}, |
---|
61 | '_old_type': 'Blog', |
---|
62 | '_type': 'Weblog'} |
---|
63 | {'_files': {'marshall': {'data': 'transformed xml', 'name': 'marshall.xml'}}, |
---|
64 | '_old_type': 'Blog', |
---|
65 | '_type': 'Weblog'} |
---|