Macros - XSLT Macro 
Page of - pēdējo reizi mainījis Helge Dahl laiks 2018/12/07 11:35 
XSLT Macro 

Helge Dahl

2018/12/07 11:35
Satura rādītājs
Samples
xml and xsl parameters
xsl parameter and content as xml document
xml parameter and content as xsl style sheet
xml parameter, content as xsl style sheet and params parameter
missing parameters
missing content

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.
Parameter	Description	Possible values	Default value	
xsl	XSLT style sheet to apply to XML	http:	  none	
xml	XML document to process	http:	  none	
params	Comma 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}}
Family name	Name	
Davolio	Nancy	
Smith	John	
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 name	Name	
Davolio	Nancy	
Smith	John	
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 name	Name	
Smith	John	
missing parameters
{{xslt /}}
 macro need at least one of  or  parameter
missing content
{{xslt xsl="attach:persons.xsl"/}}
 macro content is mandatory if only one of  or  parameter is set