source: products/quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/xslt.txt @ 1589

Last change on this file since 1589 was 277, checked in by mylan, 18 years ago

Fix publishing bug

File size: 2.2 KB
Line 
1XSLT section
2============
3
4A XSLT pipeline section lets you apply stylesheet to some XML data stored on
5item. The XSLT section blueprint name is ``quintagroup.transmogrifier.xslt``.
6
7That data need to be transformed is determined by ``source`` option. It gives
8the key in dictionay where data is stored. Dictionary is standard structure
9for storing files data in other our sections. Data is stored in item on ``_files``
10key, but this can be changed with ``files-key`` option.
11
12Usually stylesheets are used to transform data returned by ``marshall`` section.
13We 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.
25The default value for this option is ``marshall``.
26
27Which stylesheet to use is determined for every pipeline item by inspecting
28it's values stored on keys specified in ``from-key`` and ``to-key`` section
29options. These options are similar to ``from`` and ``to`` attributes in
30ZCML 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'}
Note: See TracBrowser for help on using the repository browser.