XSLT Macro

Last modified by editors on 2023/06/04 09:37

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.]page@]style.xsl

 none
xmlXML document to process

http:somewhere/document.xml
attach:[[space.]page@]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"/}}

Failed to execute the [groovy] macro. Cause: [Connection refused (Connection refused)]. Click on this message for details.

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 nameName
DavolioNancy
SmithJohn

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 nameName
DavolioNancy
SmithJohn

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 nameName
SmithJohn

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:
    
Copyright 1949-2023 Human Relations Area Files, Yale University
23.0