13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Supported languages are C#, Visual Basic, and JScript. The language attribute is notmandatory and, if not specified, defaults to JScript. The implements-prefix attribute ismandatory, however. It declares a namespace and associates the user-def<strong>in</strong>ed codewith it. The namespace must be def<strong>in</strong>ed somewhere <strong>in</strong> the style sheet. In addition, tomake use of the <strong>in</strong>struction, the style sheet must <strong>in</strong>clude the follow<strong>in</strong>gnamespace:xmlns:msxsl=urn:schemas-microsoft-com:xsltLet's see how to def<strong>in</strong>e a simple script. To start off, we'll declare the extra namespaces<strong>in</strong> the the style sheet's root node, as shown here:This declaration is necessary to be able to call the <strong>in</strong>struction. Thenamespace simply groups under a s<strong>in</strong>gle roof some user-def<strong>in</strong>ed scripts. The prefixd<strong>in</strong>o is now necessary to qualify any calls to any functions def<strong>in</strong>ed <strong>in</strong> a block. Script blocks can be def<strong>in</strong>ed as children of the node, at the samelevel as templates.The follow<strong>in</strong>g script concatenates first and last names, separated by a comma:public str<strong>in</strong>g PrepareName(str<strong>in</strong>g last, str<strong>in</strong>g first){return last + ", "+ first;}In the body of the style sheet—typically <strong>in</strong> a template—you call the function, as follows:If you enclose parameters <strong>in</strong> quotation marks, they will be treated as literals. To ensurethat the function receives only node values, use the same expressions you would usewith the select attribute of an <strong>in</strong>struction. The preced<strong>in</strong>g script runs fromthe context of a node <strong>in</strong> the follow<strong>in</strong>g schema:......276

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!