You can use this element in an xsl: The padding variable stores the number of spaces required to right-align the color name. For example, the ability of named templates to call themselves with parameters makes recursion and all the power associated with it possible.
If an XSLT variable has a value assigned by an xsl: All the stylesheet examples up to this point would work the same way if you substituted xsl: This offers two nice advantages: For example, if you xslt write attribute value a variable called templateName and stored the string "title" there, an xsl: It does this by subtracting the value of the local valueLength variable from the global fieldWidth variable.
The inner single quotation marks tell the XSLT processor that the value is a literal string and not an expression to evaluate. The double quotation marks serve a different purpose: Some XSLT processors offer a special extension function to allow the resetting of variables.
For example, the first template rule in the following stylesheet has a name attribute and not a match attribute.
XSLT variables actually have a lot more in common with constants xslt write attribute value many programming languages and are used for a similar purpose. The value-length variable stores the length of the color name using the string-length function.
Instead of the XSLT processor looking for nodes where it can apply this template, the processor will wait until the template is explicitly called with an xsl: The "titles" named template uses the passed values to create the h1 and h2 elements in the result: Here is how it looks as a complete stylesheet: The solution is to use a variable to represent this size value: It also demonstrates another nice feature of variables: It shows that the xsl: To pass the new value of "8pt" to the stylesheet when using the Saxon XSLT processor, the command line might look like this: It can treat a variable as any type of object that can be returned by an XSLT expression: If the XSLT processor had treated these number as strings, putting "8" and "2" together would get us "82".
Instead of one global bodyTextSize variable to use throughout the stylesheet, the two template rules each have their own bodyTextSize variables declared between their xsl: This ability opens up an even broader range of possibilities for how you use parameter passing in XSLT.
Other XSLT processors may require a different syntax when passing a new parameter value along from the command line, but they would still create the same result when using this stylesheet and input.
Local parameters are even more useful in template rules than XSLT local variables are, because the flexibility of passing one or more values to a template lets that template adapt to different situations.
As with any programming language, using local variables made it easier to break down the problem into pieces and to make the relationship of those pieces easier to understand.
The examples above show "top-level" variables. To do this, put the variable inside curly braces to make it an attribute value template. Note The name value specified in the xsl: Then you can pass it the important parameters each time you run it with no need to type the full Java library names for the XSLT processor and XML parser.
When really using Saxon or any other Java-based XSLT processor, it makes your life easier to store everything before the "xq The value of the select attribute must be an expression.
The only difference between applying the xq The next stylesheet uses a selection of the string manipulation functions available in XSLT to right align the result tree versions of the color elements in this document.
Variables can be "local" as well -- that is, defined inside of a template rule and only available for use within that template rule. Compare this with xq You can put the result of one or more functions in there, or even an XPath expression that retrieves a value from somewhere in the document or even from another document, using the document function.
The XSLT processor evaluates the xsl: Then, if you need to change the value when re-using the stylesheet, you only change the value assigned in the creation of that variable.
The second template sets bodyTextSize to "12pt", so the winery and grape element contents copied to the result tree by that template start with font tags that have a size value of "12pt":In this blog post I explain what attribute value templates are.
A very nice - inline - way to write XSLT, without writing too much XSLT! Setting and Using Variables and Parameters. February 7, The attribute value doesn't need curly braces to tell the XSLT processor "this is an attribute value template, variable element's contents and by a select attribute, the XSLT processor uses the one in the select attribute.
DOM Node Types DOM Node DOM NodeList DOM NamedNodeMap DOM Document DOM Element DOM Attribute DOM Text DOM CDATA DOM Comment DOM XMLHttpRequest DOM Parser XSLT Elements XSLT/XPath Functions XSLT xsl:value-of>. I have an XML input file and I'm trying to output the result of a call like: into an attribute.
XSLT Introduction XSL Languages XSLT Transform XSLT XSLT XSLT XSLT XSLT XSLT XSLT Apply XSLT on the Client XSLT on the Server XSLT Edit XML XSLT Examples. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site.Download