# XSLT Macro

Last modified by Helge Dahl on 2018/12/07 11:35

#### Export

#### Office Formats

Export as PDF Export as ODT Export as RTF

#### Other Formats

Export as HTML

XSLT Macro helps to transform XML document with XSLT style sheet.
Macro is able to retrieve XML document or style sheet from attachment or URL
XML document or else style sheet could be the content of the macro.

Parameter | Description | Possible values | Default value
--- | --- | --- | ---
xsl | XSLT style sheet to apply to XML | http:somewhere/style.xsl attach:[[space.]page@]style.xsl | none
xml | XML document to process | http:somewhere/document.xml attach:[[space.]page@]document.xml | none
params | Comma separated list of parameters name, value pair | name1=value1[,name2=value2[,...]] | none

## Samples

### xml and xsl parameters

{{xslt xsl="attach:persons.xsl" xml="attach:persons.xml"/}}

### xsl parameter and content as xml document

{{xslt xsl="attach:persons.xsl"}}
<persons>
<person username="JS1">
<name>John</name>
<family_name>Smith</family_name>
</person>
<person username="ND1">
<name>Nancy</name>
<family_name>Davolio</family_name>
</person>
</persons>
{{/xslt}}

Family name | Name
--- | ---
Davolio | Nancy
Smith | John

### xml parameter and content as xsl style sheet

{{xslt xml="attach:persons.xml"}}
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text>
|=Family name|=Name
</xsl:text>
<xsl:apply-templates select="//person">
<xsl:sort select="family_name" />
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="person">
<xsl:text>|</xsl:text>
<xsl:value-of select="family_name"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>{{/xslt}}

Family name | Name
--- | ---
Davolio | Nancy
Smith | John

### xml parameter, content as xsl style sheet and params parameter

{{xslt xml="attach:persons.xml" params="user=JS1"}}
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:param name="user"/>
<xsl:template match="/">
<xsl:text>
|=Family name|=Name
</xsl:text>
<xsl:apply-templates select="//person[@username=$user]">
<xsl:sort select="family_name" />
</xsl:apply-templates>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="person">
<xsl:text>|</xsl:text>
<xsl:value-of select="family_name"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>{{/xslt}}

Family name | Name
--- | ---
Smith | John

### missing parameters

{{xslt /}}

xslt macro need at least one of xsl or xml parameter

### missing content

{{xslt xsl="attach:persons.xsl"/}}

xslt macro content is mandatory if only one of xsl or xml parameter is set

Tags:
Created by Helge Dahl on 2010/11/02 09:30

- Comments (0)
- Attachments (2)
- Information

# Applications

# Tips

Jump to any page in the wiki with Ctrl+G or Meta+G.
See more shortcuts.

# Need help?

If you need help with XWiki you can contact:

- Community Support
- Professional Support