Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xalan="http://xml.apache.org/xalan" 
    xmlns:portal="http://uportal.org/portalUrl" 
    xmlns:rendering="http://uportal.org/renderingUrl" 
    extension-element-prefixes="portal rendering">
    
    <!-- outer portal URL element -->
    <xalan:component prefix="portal" elements="url">
        <xalan:script lang="javaclass" src="org.jasig.portal.url.PortalUrlXalanElements"/>
    </xalan:component>
    
    <!-- rendering attribute URL construction elements -->
    <xalan:component prefix="rendering" elements="attribute parameter">
        <xalan:script lang="javaclass" src="org.jasig.portal.rendering.attributes.RenderingAttributeProviderXalanElements"/>
    </xalan:component>
    
    <xsl:template match="doc">
        <!-- set rendering param for the structure attribute provider, using a string value -->
        <xsl:variable name="simpleParamUrl">
            <portal:url>
                <rendering:parameter source="structure" name="param1" value="value1"/>
            </portal:url>
        </xsl:variable>
        <test description="simple parameter set"><xsl:value-of select="$simpleParamUrl"/></test>
        
        <!-- set rendering param using an XPath expression for value -->
        <xsl:variable name="xpathParamUrl">
            <portal:url>
                <rendering:parameter source="structure" name="param1" value="{//folder[UPC:@ID='1']/@name}"/>
            </portal:url>
        </xsl:variable>
        <test description="xpath parameter set"><xsl:value-of select="$xpathParamUrl"/></test>
        
        <!-- set rendering attribute by selecting a current context node.
        The URL below will set attribute1 for a folder with ID=5 to "value1"
        -->
        <xsl:for-each select="//folder[UPC:@ID='5']">
            <xsl:variable name="simpleAttribute">
                <portal:url>
                    <rendering:attribute source="theme" name="attribute1" value="value1"/>
                </portal:url>
            </xsl:variable>
            <test description="simple atttribute of the current node"><xsl:value-of select="$simpleAttribute"/></test>
        </xsl:for-each>
        
        <!-- set rendering attributes for a specific element specified by the "select" attribute.
        The URL below will set attribute attribute3 for folder with ID=7 to the value of the type attribute on that folder
        -->
        <xsl:variable name="singleXpathNodeAttribute">
            <portal:url>
                <rendering:attribute source="theme" name="attribute2" value="{//folder[UPC:@ID='7']/@type}" select="//folder[UPC:@ID='7']"/>
            </portal:url>
        </xsl:variable>
        <test description="simple atttribute of a single selected node"><xsl:value-of select="$singleXpathNodeAttribute"/></test>
        
        <!-- set rendering attributes for a set of elements using "select" attribute.
        The URL below will set attribute attribute3 to "value3" for all folders with attribute type="someType"
        -->
        <xsl:variable name="multipleXpathNodesAttribute">
            <portal:url>
                <rendering:attribute source="structure" name="attribute3" value="value3" select="//folder[UPC:@type='someType']"/>
            </portal:url>
        </xsl:variable>
        <test description="xpath atttribute of multiple selected nodes"><xsl:value-of select="$multipleXpathNodesAttribute"/></test>

        <!-- use the extension element directly, without declaring a variable first 
             Note that this can not be done within <xsl:attribute/> element
        -->
        <test description="using extension element directly, without a variable declaration">
            <portal:url>
                <rendering:attribute source="structure" name="attribute3" value="value3" select="//folder[UPC:@type='someType']"/>
            </portal:url>
        </test>

    </xsl:template>
    
</xsl:stylesheet>