Microsofts XSLT tools Global Parameters

page 66 public class GlobalParameters { public static void parseAndProcessString sourceID, String xslID, String outputID { try { TransformerFactory tfactory = TransformerFactory.newInstance; Transformer transformer = tfactory.newTransformernew StreamSourcexslID; Use the setParameter method to set global parameters transformer.setParameterstartX, new Integer50; transformer.setParameterbaseColor, magenta; transformer.transformnew StreamSourcenew FilesourceID, new StreamResultnew FileoutputID; } catch TransformerConfigurationException tce { System.err.printlnException: + tce; } catch TransformerException te { System.err.printlnException: + te; } } public static void mainString argv[] throws java.io.IOException, org.xml.sax.SAXException { GlobalParameters gp = new GlobalParameters; gp.parseAndProcessxyz.xml, params.xsl, output.text; } } Notice that we used the setParameter method to set global parameters for the Transformer object before we invoke the transform method. This transformation generates the following results in output.text: Global parameters example The value of startX is: 50 The value of baseColor is: magenta

4.5 Variables

If we use logic to control the flow of our stylesheets, well probably want to store temporary results along the way. In other words, well need to use variables. XSLT provides the xsl:variable element, which allows you to store a value and associate it with a name. The xsl:variable element can be used in three ways. The simplest form of the element creates a new variable whose value is an empty string . Heres how it looks: xsl:variable name=x This element creates a new variable named x , whose value is an empty string. Please hold your applause until the end of the section. You can also create a variable by adding a select attribute to the xsl:variable element: xsl:variable name=favouriteColour select=blue In this case, weve set the value of the variable to be the string blue. Notice that we put single quotes around the value. These quotes ensure that the literal value blue is used as the