Written by     For umbraco versions: All

Reference
A look at the mysterious macro parameter types and their syntax.

Contents

Working with parameters in xslt

Okey so sofar we've setup a simple xslt script, added 2 parameters and picked some simple data for the parameters when we inserted the macro in a template. 

So what does the 2 parameters return?

The <xsl:copy-of select="/macro/text" /> returns:

<text>Hello World</text>

The <xsl:copy-of select="/macro/contentTree" /> returns:

<contentTree nodeID="1053">
<node id="1053" version="a1e061ab-3109-4690-9374-bd0f05882e9b"
parentID="1052" level="2" writerID="0" creatorID="0"
nodeType="1044" template="1043" sortOrder="1"
createDate="2005-12-30T14:01:21" updateDate="2007-06-21T14:06:32"
nodeName="About" urlName="about" writerName="Administrator"
creatorName="Administrator" nodeTypeAlias="wwTextpage"
path="-1,1052,1053">
<data alias="bodyText">Body text...</data>
<data alias="header">My Header text...</data>
</node>
</contentTree>

So as you can see: the text parameter simple sends the text string we entered to the macro and the contentTree paramater sends a big chunk of xml describing the node we selected. If the node had any child nodes these would also be send to the xslt macro as xml.

Explaining how the parameters are send to the macro

When you setup a macro parameter for a xslt macro. You basicly tell umbraco to send some xml to the xslt script. This xml looks something like this:

<macro>
<parameteralias1>Value</parameteralias1>
<parameteralias2>Value</parameteralias2>
</macro>

So with this infomation along with some basic xpath we can query the xml from the parameters. which is what are doing with "/macro/text" which will get the value from the "text" parameter and the "/macro/contentTree" which will get the value of the parameter with the alias "contentTree" we could then go on a do some basic xpath work on the contentTree macro to return the selected nodes name like this:

<xsl:value-of select="/macro/contentTree/node/nodeName"/> 

or get it's bodyText value with
<xsl:value-of select="/macro/contentTree/node/data [@alias = 'bodyText'"/>

Okey so now we are able to define parameters, input some data, get the data to the xslt and work with it in the xslt file. Let's continue to take a look at all the different types of parameters and what they look like in xslt