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.

Table 7-3: XSLT Instructions <strong>for</strong> Control FlowInstruction ……DescriptionApplies the <strong>in</strong>ternal template only ifthe specified XPath expressionevaluates to true.Similar to the C# switch statement;represents a multiple-choicestatement. Each test is expressedus<strong>in</strong>g an statement,while the elementrepresents the default choice. Thestatement evaluates all the blocks until the testexpression returns true. When thathappens, the correspond<strong>in</strong>gtemplate is applied. If no test issuccessful, the template is <strong>in</strong>voked.Although this list of commands lacks a <strong>for</strong> statement, you can still realize a loop thatruns a specified number of times by us<strong>in</strong>g the XPath position function. Of course,position returns the <strong>in</strong>dex of the current context node and is not a general variablecounter. On the other hand, XSLT <strong>in</strong>structions are designed to work on XPath nodesets,not to arrange general-purpose programs.Layout InstructionsA typical task <strong>for</strong> an XSLT script is the creation of new elements and attributes.Sometimes attributes and node elements can be hard-coded <strong>in</strong> script; sometimes this isjust impossible to do. The XSLT statements listed <strong>in</strong> Table 7-4 let you programmaticallycreate layout elements.Table 7-4: XSLT Instructions <strong>for</strong> LayoutInstructionDescriptionCreates an element with thespecified name. The namespaceattribute <strong>in</strong>dicates the URI of thecreated element, if any. The element conta<strong>in</strong>s atemplate <strong>for</strong> the attributes andchildren of the created element.Creates an attribute node andattaches it to an output element.The name attribute denotes thename of the attribute, andnamespace <strong>in</strong>dicates thenamespace URI, if any. Thecontents of this element specify thevalue of the attribute. Note that can also be useddirectly on output elements, notonly <strong>in</strong> conjunction with.243

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

Saved successfully!

Ooh no, something went wrong!