MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT...

13
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi

Transcript of MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT...

Page 1: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

MC 365 – Software Engineering

Presented by:John RistucciaShawn PostsNdi Sampson

XSLTIntroduction BCi

Page 2: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

BackgroundTitle: EE and DC

• What is XSLT?• XSLT stands for Extensible Stylesheet Language Transformations•XSLT is designed for use as part of XSL, which is a stylesheet language for XML.

• What is XML and why does it need XSL• Extensible Markup Language is a set of semantic rules designed to break up a document into hierarchical and easily identifiable parts.

• XML Has three important features…

What

can BCi Do?

Page 3: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Background ContinuedTitle: EE and DC

• XML is a meta-markup language•Instead of having a specified set of tags to draw from, you define your own as you need them; allowing for immense versatility and Domain-specific markup languages.

• XML Follows a Strict hierarchical structure.

• Every well-formed XML document is a tree; having a root, children, and leaves. Nodes can be elements, text, attributes, comments, processing instructions, or namespaces.

• XML contains only structural and semantic info

•XML documents contain no formatting information – hence XSL/XSLT.

What

can BCi Do?

Page 4: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Background ContinuedTitle: EE and DC

• To ReiterateXSL (Extensible Stylesheet Language) provides a language for adding formatting and structure to an XML document. The process of XSL Transformation basically takes in one XML document and transforms it into a different XML document (usually but not always a well-formed HTML document viewable by a web browser)

What

can BCi Do?

Page 5: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Advantages and DisadvantagesTitle: EE and DC

• Advantages• Easy to merge data into XML data into a presentation• More resilient to change in the details of the XML document than in the low-level DOM (Document Object Model) and SAX (Simple API for XML)• Database inquiries can be returned in XML

• Insensitive to column order

•Disadvantages• Memory intensive and suffers a performance penalty• Difficult to implement complicated business rules• Have to learn a new language• Can’t change the value of variables (requires recursion)

What

can BCi Do?

Page 6: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

XSL TransformationsTitle: EE and DC

• Use• X-Path to identify (select) parts of an XML document• XSLT Templates to apply transformations

•Requires• Well formed XML document• XSL document (stylesheet) that contains formatting and transformation templates• XSLT parser to perform the transformations

What

can BCi Do?

Page 7: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Steps for Translating a DocumentTitle: EE and DC

1. Tell a system which parser to use2. Establish a factory in which to

create transformations3. Create a transformer for a

particular style sheet4. Invoke the transformer to process

the document

What

can BCi Do?

Page 8: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Title: EE and DC Who can use

BCi?XSLT Example

<- XML

<- XSL

XSLT ->

Another example

Page 9: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

XSLT Stylesheet ElementsTitle: EE and DC

• Matching and Selecting Templates

• xsl:template• xsl:apply-template• xsl:value-of

•Branching Elements• xsl:for-each• xsl:if• xsl:choose

What

can BCi Do?

Page 10: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Example of xsl:ifTitle: EE and DC

• xsl:if test = “expression”• Evaluate the expression to a boolean and if true, applies the template body• XSLT has not else if construct (use choose)

<xsl:template match = “ROW”><!-- select first node in the node set --><xsl:if test= “position() = first()”>

<xsl:value of select = “.” /></xsl:if></xsl:template>

<xsl:template match= “ROW”><!– Select if current node has children -->

<xsl:if test = “node()”><xsl:apply-templates/>

</xsl:if></xsl:template>

What

can BCi Do?

Page 11: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Title: EE and DCCopying:• xsl:copy, copies the current node• xsl:apply-templates, processes the children of the current node

ex. <xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="title"><xsl:copy>

<xsl:apply-templates/></xsl:copy>

</xsl:template></xsl:stylesheet>

• xsl:copy-of element, can copy the entire subtree of each node that the template selects

ex. <xsl:template match="title“><xsl:copy-of select="*"/>

</xsl:template>

Requirements

?Some Simple XSLT

Page 12: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Some More Simple XSLTPotential Problems?

Deleting:• <xsl:template match="nickname"> </xsl:template>

<xsl:template match="project[@status='canceled']"> </xsl:template>

•While a match value of "project" would delete all the project elements from the output, the match value shown will only delete project elements whose status

attributes have the string "canceled" as their value.

Page 13: MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.

Some More Simple XSLT

Changing Element Names:ex.<xsl:template match="article">

<html><xsl:apply-templates/>

</html></xsl:template>

• This template rule tells an XSLT processor to take any “article” element fed to it as input, and output its contents surrounded by html tags