# Wiki source code of 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
Hide last authors

| 1.1 | 1 | XSLT Macro helps to transform XML document with XSLT style sheet.
|  | 2 | Macro is able to retrieve XML document or style sheet from attachment or URL
|  | 3 | XML document or else style sheet could be the content of the macro.
|  | 4 |
|  | 5 | |=Parameter|=Description|=Possible values|=Default value
|  | 6 | |xsl|XSLT style sheet to apply to XML|(((http~://somewhere/style.xsl
|  | 7 | attach~:~[[space.]page@]style.xsl)))| none
|  | 8 | |xml|XML document to process|(((http~://somewhere/document.xml
|  | 9 | attach~:~[[space.]page@]document.xml)))| none
|  | 10 | |params|Comma separated list of parameters name, value pair|(((name1=value1[,name2=value2[,...~]])))| none
|  | 11 |
|  | 12 | == Samples ==
|  | 13 | ===xml and xsl parameters===
|  | 14 | {{code}}{{xslt xsl="attach:persons.xsl" xml="attach:persons.xml"/}}{{/code}}
|  | 15 |
|  | 16 | {{xslt xsl="attach:persons.xsl" xml="http://localhost:8080/xwiki/bin/download/Macros/xslt/persons.xml"/}}
|  | 17 |
|  | 18 | ===xsl parameter and content as xml document==
|  | 19 | {{code}}{{xslt xsl="attach:persons.xsl"}}
|  | 20 | <persons>
|  | 21 | <person username="JS1">
|  | 22 | <name>John</name>
|  | 23 | <family_name>Smith</family_name>
|  | 24 | </person>
|  | 25 | <person username="ND1">
|  | 26 | <name>Nancy</name>
|  | 27 | <family_name>Davolio</family_name>
|  | 28 | </person>
|  | 29 | </persons>
|  | 30 | {{/xslt}}
|  | 31 | {{/code}}
|  | 32 |
|  | 33 | {{xslt xsl="attach:persons.xsl"}}
|  | 34 | <persons>
|  | 35 | <person username="JS1">
|  | 36 | <name>John</name>
|  | 37 | <family_name>Smith</family_name>
|  | 38 | </person>
|  | 39 | <person username="ND1">
|  | 40 | <name>Nancy</name>
|  | 41 | <family_name>Davolio</family_name>
|  | 42 | </person>
|  | 43 | </persons>
|  | 44 | {{/xslt}}
|  | 45 |
|  | 46 | ===xml parameter and content as xsl style sheet==
|  | 47 | {{code}}{{xslt xml="attach:persons.xml"}}
|  | 48 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|  | 49 | <xsl:output method="text"/>
|  | 50 | <xsl:template match="/">
|  | 51 | <xsl:text>
|  | 52 | |=Family name|=Name
|  | 53 | </xsl:text>
|  | 54 | <xsl:apply-templates select="//person">
|  | 55 | <xsl:sort select="family_name" />
|  | 56 | </xsl:apply-templates>
|  | 57 | <xsl:text>
|  | 58 | </xsl:text>
|  | 59 | </xsl:template>
|  | 60 | <xsl:template match="person">
|  | 61 | <xsl:text>|</xsl:text>
|  | 62 | <xsl:value-of select="family_name"/>
|  | 63 | <xsl:text>|</xsl:text>
|  | 64 | <xsl:value-of select="name"/>
|  | 65 | <xsl:text>
|  | 66 | </xsl:text>
|  | 67 | </xsl:template>
|  | 68 | </xsl:stylesheet>{{/xslt}}{{/code}}
|  | 69 |
|  | 70 | {{xslt xml="attach:persons.xml"}}
|  | 71 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|  | 72 | <xsl:output method="text"/>
|  | 73 | <xsl:template match="/">
|  | 74 | <xsl:text>
|  | 75 | |=Family name|=Name
|  | 76 | </xsl:text>
|  | 77 | <xsl:apply-templates select="//person">
|  | 78 | <xsl:sort select="family_name" />
|  | 79 | </xsl:apply-templates>
|  | 80 | <xsl:text>
|  | 81 | </xsl:text>
|  | 82 | </xsl:template>
|  | 83 | <xsl:template match="person">
|  | 84 | <xsl:text>|</xsl:text>
|  | 85 | <xsl:value-of select="family_name"/>
|  | 86 | <xsl:text>|</xsl:text>
|  | 87 | <xsl:value-of select="name"/>
|  | 88 | <xsl:text>
|  | 89 | </xsl:text>
|  | 90 | </xsl:template>
|  | 91 | </xsl:stylesheet>{{/xslt}}
|  | 92 |
|  | 93 | ===xml parameter, content as xsl style sheet and params parameter==
|  | 94 | {{code}}{{xslt xml="attach:persons.xml" params="user=JS1"}}
|  | 95 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|  | 96 | <xsl:output method="text"/>
|  | 97 | <xsl:param name="user"/>
|  | 98 | <xsl:template match="/">
|  | 99 | <xsl:text>
|  | 100 | |=Family name|=Name
|  | 101 | </xsl:text>
|  | 102 | <xsl:apply-templates select="//person[@username=$user]">
|  | 103 | <xsl:sort select="family_name" />
|  | 104 | </xsl:apply-templates>
|  | 105 | <xsl:text>
|  | 106 | </xsl:text>
|  | 107 | </xsl:template>
|  | 108 | <xsl:template match="person">
|  | 109 | <xsl:text>|</xsl:text>
|  | 110 | <xsl:value-of select="family_name"/>
|  | 111 | <xsl:text>|</xsl:text>
|  | 112 | <xsl:value-of select="name"/>
|  | 113 | <xsl:text>
|  | 114 | </xsl:text>
|  | 115 | </xsl:template>
|  | 116 | </xsl:stylesheet>{{/xslt}}{{/code}}
|  | 117 |
|  | 118 | {{xslt xml="attach:persons.xml" params="user=JS1"}}
|  | 119 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|  | 120 | <xsl:output method="text"/>
|  | 121 | <xsl:param name="user"/>
|  | 122 | <xsl:template match="/">
|  | 123 | <xsl:text>
|  | 124 | |=Family name|=Name
|  | 125 | </xsl:text>
|  | 126 | <xsl:apply-templates select="//person[@username=$user]">
|  | 127 | <xsl:sort select="family_name" />
|  | 128 | </xsl:apply-templates>
|  | 129 | <xsl:text>
|  | 130 | </xsl:text>
|  | 131 | </xsl:template>
|  | 132 | <xsl:template match="person">
|  | 133 | <xsl:text>|</xsl:text>
|  | 134 | <xsl:value-of select="family_name"/>
|  | 135 | <xsl:text>|</xsl:text>
|  | 136 | <xsl:value-of select="name"/>
|  | 137 | <xsl:text>
|  | 138 | </xsl:text>
|  | 139 | </xsl:template>
|  | 140 | </xsl:stylesheet>{{/xslt}}
|  | 141 |
|  | 142 | === missing parameters ===
|  | 143 | {{code}}{{xslt /}}{{/code}}
|  | 144 |
|  | 145 | {{xslt /}}
|  | 146 |
|  | 147 | === missing content===
|  | 148 | {{code}}{{xslt xsl="attach:persons.xsl"/}}{{/code}}
|  | 149 |
|  | 150 | {{xslt xsl="attach:persons.xsl"/}}

# Applications

# Tips

Did you know that you can improve XWiki? Take 5 minutes to fill this survey and help this open source project!

# Need help?

If you need help with XWiki you can contact:

- Community Support
- Professional Support