Variables
- <xsl:variable name="xxx">definition</xsl:variable>
-- sets up variable, string value, not numeric
- If you want a numeric value, use <xsl:variable name="x" select="number(2)"
/>
- you cannot change the value of a variable once it is set
- Simple example
- <xsl:copy-of select="$myvariable" /> -- gets the variable,
and works with most functions, but not within brackets.
- A more involved example
- {$myvariable} if it is used inside a bracket link (can't use <a href="mailto:<xsl:copy-of
select="$myvariable" /> have to use <a href="mailto:{$myvariable}
">
- String example
- <xsl:variable name="colorType" select=" 'boxedRed' "/>
-- internal single quotes selects the string you want to use.
- Node example
- need to use a namespace to get this to work
- xmlns:msxml="urn:schemas-microsoft-com:xslt"
- set up the "temp_redundant" variable
- sort the list of authors by alphabet
- get the last name
- copy into a variable named "temp_redundant"
- set up a "redundant" variable
- put "temp_redundant" list into the node-set called "redundant"
- make a "temp_reduced" variable
- look at our "redundant" nodeset and save the position of this
last name
- save this last name as the "current" name
- do a "test"
- if pos=1
- or not (current = redundant/*[pos - 1]
) (in the loop, this will check each current)
- The "/" gets us a child of the redundant node
- the * gets us any child[pos-1]
- copy name into temp_reduced
- set up "reduced" variable
- convert "temp_reduced" into the node-set called "reduced"
- print the "reduced" variable
- count the number of books the writer actually contributed
- <xsl:value-of select="count($redundant/Author[.=$current])"
- use the count function
- reference the redundant nodeset
- reference the Author child predicate = "." stands for self
- =$current is the current list
- Parameters
- variable that can be set by an outside call
- <xsl:param name="paramName" />
- This one would evaluate to an empty string or false
- Usually used for DOM code to fill the contents before processing the
XSLT
- <xsl:param name="paramName" select="xpathExpression"
/>
- Default value, if no external value is given
- can be a string, number, or node-set
- This is overwritten if the parameter is set from the outside
- <xsl:param name="paramName">XML Tree Fragment Content
</xsl:param>
- parameter declarations must precede variables and most other code
- parameter declarations can only be placed at the beginning of the template
definition
- makes it difficult to put generated code directly into parameters
XSL Explanation
Templates -- built-in templates, adding modularity,
includes and imports
Templates Examples--
XSL Namespaces-- using namespaces with XSL
XPath -- getting around XSL
XPath Examples
Functions-- using functions
Functions Examples
Variables and Parameters