page_white_codeHelps to transform XML document with XSLT style sheet
TypeXAR
Developed by

Arnaud

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

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.

ParameterDescriptionPossible valuesDefault value
xslXSLT style sheet to apply to XML

http:somewhere/style.xsl
attach:[[space.][email protected]]style.xsl

 none
xmlXML document to process

http:somewhere/document.xml
attach:[[space.][email protected]]document.xml

 none
paramsComma 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}}

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}}

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}}

Tested on

This extension has been tested with the following configurations.

Extension VersionXWiki FlavorNotes
1.0XWiki Enterprise 3.5
1.1XWiki Enterprise 4.5.1
1.1XWiki Enterprise 6.0.1

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Import the XAR and visit page Macros.xslt

Release Notes

v1.1

Add params macro's parameter to give <xsl:params/> to the style-sheet

v1.0

Initial version

Tags:
Created by Vincent Massol on 2011/10/19 13:41
    

Get Connected