WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

XMLTemplate ["string"]

yields a TemplateObject that represents an XML template to be applied using functions like TemplateApply .

XMLTemplate [src]

uses File [], URL [], or CloudObject [] as the source for the string template.

XMLTemplate [form,args]

yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
InsertionFunction  
CombinerFunction  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Related Guides
Related Workflows
Related Links
History
Cite this Page

XMLTemplate ["string"]

yields a TemplateObject that represents an XML template to be applied using functions like TemplateApply .

XMLTemplate [src]

uses File [], URL [], or CloudObject [] as the source for the string template.

XMLTemplate [form,args]

yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.

Details and Options

  • The following basic tags can be used in the XML:
  • <wolfram:slot> TemplateSlot
    <wolfram:expr> TemplateExpression
    <wolfram:if> TemplateIf
    <wolfram:which> multiple TemplateIf
    <wolfram:sequence> TemplateSequence
    <wolfram:with> TemplateWith
    <wolfram:template> TemplateObject
    <wolfram:get> Get
    <wolfram:comment> comment to be ignored
    <wolfram:verbatim> verbatim XML
  • <wolfram:slotinserter=f> specifies the option setting InsertionFunction->f in TemplateSlot .
  • <wolfram:exprinserter=f> specifies the option setting InsertionFunction->f in TemplateExpression .
  • <wolfram:slot/> is equivalent to TemplateSlot [1].
  • <wolfram:if test=test>body</wolfram:if> specifies that body should be rendered if test evaluates to True .
  • <wolfram:which> ... </wolfram:which> can enclose any number of <wolfram:if ...> ... </wolfram:if>, and optionally a single <wolfram:else> ... </wolfram:else>. The "if" tests are evaluated in sequence, with the first one that evaluates to True being the final form of the "which".
  • <wolfram:sequence attr>body</wolfram:sequence> supports the following attributes:
  • values (required) list or association over which to repeat body
    slot 1 name of the template slot provided to body
    index 2 name of the position index provided to body
    delimiters Sequence [] delimiters to insert between repeats of body
    default Sequence [] form to use if there are no values
    inserter Inherited setting for InsertionFunction option
  • <wolfram:with key1=val1 key2=val2 ...>body</wolfram:with> specifies that keyi should be replaced by vali in body when the template is applied.
  • <wolfram:template attr>body</wolfram:template> supports the following attributes, which define options for the TemplateObject to be used with body:
  • inserter Inherited setting for InsertionFunction option
    combiner Inherited setting for CombinerFunction option
  • <wolfram:get attr/> supports the following attributes:
  • path (required) file or URL path
    inserter Inherited setting for InsertionFunction option
    combiner Inherited setting for CombinerFunction option
  • XMLTemplate has the following options:
  • InsertionFunction "HTMLFragment" function or format to apply before inserting expressions
    CombinerFunction StringJoin function to apply to combine pieces before returning a result
  • In XMLTemplate [File []] and XMLTemplate [URL []], the content of the source file etc. is imported as a string.

Examples

open all close all

Basic Examples  (2)

Apply an XML template with slots named a and b:

An equivalent form using TemplateApply :

XMLTemplate supports the same syntax as StringTemplate ; expressions in <**> are evaluated when the template is applied:

Include a template slot as well as an expression in the template string:

An equivalent syntax using XML tags:

String template syntax is useful when you need to inject data inside XML attributes:

Scope  (4)

File is fully supported:

Templates can be hosted in the Wolfram Cloud:

The second argument of XMLTemplate can be used to bound data to the template:

URL can be used to fetch templates:

Options  (2)

InsertionFunction  (1)

The inserter attribute can be a function or a string chosen between $ExportFormats :

The above code is equivalent to:

InsertionFunction can be anything:

CombinerFunction  (1)

The combiner function also accepts formats:

The combiner function can be anything:

Applications  (9)

<wolfram:slot id='...' inserter='...'>...</wolfram:slot>

Simple usage:

Working with default and inserter:

<wolfram:expr inserter='...'>...</wolfram:expr>

Simple usage:

Working with data and inserter:

<wolfram:if test='...'>...</wolfram:if>

Test can be any expression:

<wolfram:which><wolfram:if test='...'>...</wolfram:if></wolfram:which>

Use "which" to nest multiple "else if" clauses:

<wolfram:sequence values='...' ...>...</wolfram:sequence>

Basic usage:

Using named variables:

Using the insertion function:

Using the default value (a StringTemplate ):

Using a delimiter:

<wolfram:with key1ドル='val1ドル' ...>...</wolfram:with>

<wolfram:get path='...'><wolfram:slot id='...'/>...</wolfram:get>

Include a template from "path". "Path" is a StringTemplate :

Change insertion and combiner functions for the output:

Extending a template. Example of a template for an HTML page:

Using "get" to override slots:

<wolfram:template ...>...</wolfram:template>

Use "template" to create a fragment that overrides the insertion and combiner functions:

Combine templates and edit an external template:

<wolfram:comment>...</wolfram:comment>

<wolfram:verbatim>...</wolfram:verbatim>

Use "verbatim" to avoid parsing. An optional insertion function is allowed:

Properties & Relations  (1)

XMLTemplate evaluates to a TemplateObject :

Possible Issues  (1)

Data in the second argument of XMLTemplate takes precedence over arguments in TemplateApply :

Neat Examples  (1)

You can deploy an XMLTemplate to the cloud. When you visit the URL, TemplateApply will render the template on each visit:

Related Workflows

Wolfram Research (2014), XMLTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/XMLTemplate.html.

Text

Wolfram Research (2014), XMLTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/XMLTemplate.html.

CMS

Wolfram Language. 2014. "XMLTemplate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/XMLTemplate.html.

APA

Wolfram Language. (2014). XMLTemplate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/XMLTemplate.html

BibTeX

@misc{reference.wolfram_2025_xmltemplate, author="Wolfram Research", title="{XMLTemplate}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/XMLTemplate.html}", note=[Accessed: 17-November-2025]}

BibLaTeX

@online{reference.wolfram_2025_xmltemplate, organization={Wolfram Research}, title={XMLTemplate}, year={2014}, url={https://reference.wolfram.com/language/ref/XMLTemplate.html}, note=[Accessed: 17-November-2025]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /