Difference between revisions of "Command/xmlinclude"
< Command
Jump to navigation
Jump to search
(Create entire page) |
m (Inserted Hans' explanation from mailing list.) |
||
Line 38: | Line 38: | ||
== Example == | == Example == | ||
+ | |||
+ | Here is an example how to use {{cmd|xmlinclude}} to combine several xml files into one document. The xml files represent single chapters of a book project. Their structure is: | ||
+ | |||
+ | <xmlcode> | ||
+ | <chapter title="Chapter 1"> | ||
+ | <content> | ||
+ | Text of chapter | ||
+ | </content> | ||
+ | </chapter> | ||
+ | </xmlcode> | ||
+ | |||
+ | Then, one master file combines all these into one structure via the xi:include element [http://www.w3.org/TR/2003/WD-xinclude-20031110/]: | ||
<xmlcode> | <xmlcode> | ||
− | < | + | <document> |
− | < | + | <xi:include href="chapter_1.xml"/> |
− | < | + | <xi:include href="chapter_2.xml"/> |
− | </ | + | </document> |
</xmlcode> | </xmlcode> | ||
+ | |||
+ | And finally, you process this with a master tex file: | ||
<texcode> | <texcode> | ||
− | \xmlinclude. | + | \startxmlsetups xml:setups |
+ | \xmlinclude{#1}{xi:include}{href} | ||
+ | \xmlsetsetup{#1}{document|chapter}{xml:*} | ||
+ | \stopxmlsetups | ||
+ | |||
+ | \xmlregistersetup{xml:setups} | ||
+ | |||
+ | \startxmlsetups xml:document | ||
+ | \xmlflush{#1} | ||
+ | \stopxmlsetups | ||
+ | |||
+ | \startxmlsetups xml:chapter | ||
+ | \startchapter[title=\xmlatt{#1}{title}] | ||
+ | \xmlall{#1}{content} | ||
+ | \stopchapter | ||
+ | \stopxmlsetups | ||
+ | |||
+ | \starttext | ||
+ | |||
+ | \xmlprocessfile{main}{master.xml}{} | ||
+ | |||
+ | \stoptext | ||
</texcode> | </texcode> | ||
Latest revision as of 17:16, 17 December 2012
\xmlinclude
Syntax
\xmlinclude{...}{...}{...} | |
{...} | xmldata, usually main |
{...} | pattern that matches tags that stand for 'include external file'. Default: include |
{...} | names of attribute containing URL of file to include, separated by pipes. Default: href |
Description
\xmlinclude{main}{include}{filename|href|name} merges XML trees in external files into the tree called main
. External files are merged in at every include
tag; which file to merge in is determined by looking at the filename
attribute; if that is absent the href
and name
attributes are tried in order.
Further behaviour:
- If no attribute is specified,
href
is assumed. - If the file is empty or not found, the inclusion tag is replaced with nothing.
- Inclusion is recursive: if there are inclusion tags in the external tree you pull in, then they, in turn are acted on, too. If you do not want recursive inclusion, you must use the
xml.include))
command directly, like so:
\ctxlxml{include("main","include","filename|href",false)} % false means no recursion
Example
Here is an example how to use \xmlinclude to combine several xml files into one document. The xml files represent single chapters of a book project. Their structure is:
<chapter title="Chapter 1"> <content> Text of chapter </content> </chapter>
Then, one master file combines all these into one structure via the xi:include element [1]:
<document> <xi:include href="chapter_1.xml"/> <xi:include href="chapter_2.xml"/> </document>
And finally, you process this with a master tex file:
\startxmlsetups xml:setups \xmlinclude{#1}{xi:include}{href} \xmlsetsetup{#1}{document|chapter}{xml:*} \stopxmlsetups \xmlregistersetup{xml:setups} \startxmlsetups xml:document \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:chapter \startchapter[title=\xmlatt{#1}{title}] \xmlall{#1}{content} \stopchapter \stopxmlsetups \starttext \xmlprocessfile{main}{master.xml}{} \stoptext
See also
Help from ConTeXt-Mailinglist/Forum
All issues with: