Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Initial draft of how-to guide for nested macros with XSLT macro

This article explains how you can nest macros within the XSLT macro.

Table of Contents
minLevel2
maxLevel6
outlinefalse
styledisc
typelist
printablefalse

XML code to add nested macros

To add nested macros in the XSLT macro, add the XML code in the following format to the XML file to be displayed:

Code Block
languagexml
<ac:macro> 
  <xsl:attribute name="ac:name">expand</xsl:attribute> 
  <ac:parameter> 
       <xsl:attribute name="ac:name">title</xsl:attribute> 
       <xsl:value-of select="@name"/> 
  </ac:parameter>  
  <ac:rich-text-body> 
    ...... 
 </ac:rich-text-body> 
</ac:macro>

The codes mentioned in this article are not meant for general use other than the format mentioned above. The code samples simply illustrate the format and usage of the given format to display the required XML file contents.

Example - Display CD catalog from an XML file

In this example, the requirement is to display a CD catalog with each CD’s title, artist, and country from where the artist originates.

Points to note for this example:

  • The catalog information is in the form of an XML file and is available at a remote location. Here, a profile is used to access the required file.
    See an article about profiles to learn more. Note, the article focuses on data center/server and depicts HTML macro examples. Use the same process to create profiles in cloud and use the Profile parameter in the XSLT macro to access the required file.

  • The XSL definitions are entered directly in the macro editor.

The details entered in the XSLT macro editor are as follows:

...

The code in the macro editor contains the nested macro used to list out the details such as the title, the artist, and the country where the CD was made. The XSL definition entered directly in the macro editor is as follows:

Code Block
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" version="1.0">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
      <xsl:for-each select="catalog/cd">
        <ac:macro>
          <xsl:attribute name="ac:name">expand</xsl:attribute>
          <ac:parameter>
			<xsl:attribute name="ac:name">title</xsl:attribute>
			<xsl:value-of select="title"/>
		  </ac:parameter>
		  <ac:rich-text-body>
			  <div>
                <h3>Title:</h3><xsl:value-of select="title"/>
              </div>
              <div>
                <h3>Artist:</h3><xsl:value-of select="artist"/>
              </div>
              <div>
                <h3>Country:</h3><xsl:value-of select="country"/>
              </div>
		  </ac:rich-text-body>
        </ac:macro>
      </xsl:for-each>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

The content displayed after publishing the page appears as:

...

Example - API functions list

In this example, a list of API functions are to be displayed on a page.

Points to note for this example:

  • The details of the services are available in an XML file and the location is specified in the Location of XML Code macro parameter.

  • The XSL file location is entered in the Location of XSL Code macro parameter. Thus, the macro editor is left blank.

The details entered in the XSLT macro editor are as follows:

...

The content displayed on the page after publishing is as follows:

...

If you face any difficulties in using this feature, contact our Support team for help.