Top Banner
Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden. Using XSLT To Using XSLT To Transform XML Transform XML Brian E. Travis Brian E. Travis Architag International Corp Architag International Corp [email protected] [email protected] 9-333 9-333
20

Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Mar 27, 2015

Download

Documents

Emma Ruiz
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Using XSLT To Using XSLT To Transform XMLTransform XML

Brian E. TravisBrian E. TravisArchitag International CorpArchitag International [email protected]@architag.com

9-3339-333

Page 2: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.
Page 3: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLXSLExtensible Stylesheet LanguageExtensible Stylesheet Language

HTML: "Format without Structure"HTML: "Format without Structure" Typesetting languageTypesetting language Not extensibleNot extensible

CSS: "Enhanced Format, No Structure"CSS: "Enhanced Format, No Structure" Stylesheet languageStylesheet language Overrides default formatting for HTML, but annot Overrides default formatting for HTML, but annot

change basic structure of the documentchange basic structure of the document XML: "Structure Without Format"XML: "Structure Without Format"

Defines "elements" using "tags"Defines "elements" using "tags" Creates hierarchical structure of information setCreates hierarchical structure of information set

Page 4: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLTXSLT"Adding Format to Structure""Adding Format to Structure"

Transforms XML to XMLTransforms XML to XML Declarative programming languageDeclarative programming language Creates formatted outputCreates formatted output Does limited processingDoes limited processing

Page 5: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

QuizQuiz

May 5, 2000May 5, 2000

<I>May 5, 2000</I><I>May 5, 2000</I>

<birthday>May 5, 2000</birthday><birthday>May 5, 2000</birthday>

Page 6: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLT OperationXSLT Operation

XSLXSL

TransformerTransformer

Output (x)Output (x)

StylesheetStylesheetxmlns:xslxmlns:xsl

Source TreeSource Tree(your XML)(your XML)

XSLTXSLT

Page 7: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Example In XRayExample In XRay

Page 8: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLT Stylesheet ArchitectureXSLT Stylesheet Architecture

<xsl:stylesheet <xsl:stylesheet

version="1.0"version="1.0"

xmlns:xsl="http://xmlns:xsl="http://

www.w3.org/1999/www.w3.org/1999/

XSL/Transform">XSL/Transform">

......

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

Start tag for stylesheet Start tag for stylesheet

document, containing document, containing

XSL Namespace XSL Namespace

indicatorindicator

Template rules and Template rules and

other stuffother stuff End of stylesheetEnd of stylesheet

Page 9: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLT Template RuleXSLT Template Rule<xsl:template match="chapter/title">

<DIV STYLE="font-family:sans-serif;font-weight:bold;color:blue;"><xsl:apply-templates/>

</DIV></xsl:template>

Page 10: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

PatternsPatterns

ParagraphParagraph ElementElement

abstract/paragraphabstract/paragraph ParentParent

chapter//quotechapter//quote AncestorAncestor

chapter[synopsis]chapter[synopsis] FilterFilter

list[@type]list[@type] Attribute filter Attribute filter

(specified)(specified)

list[@type=‘ordered’list[@type=‘ordered’

]]Attribute filter (value)Attribute filter (value)

Page 11: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

<xsl:apply-templates/>

<xsl:value-of/>

<xsl:template match=“something”/>

XSLT Template RuleXSLT Template Rule

Page 12: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLT StylesheetXSLT Stylesheet

<?xml version="1.0"?><xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="weather"><H1><xsl:value-of select="@type"/></H1><xsl:apply-templates/><HR/>

</xsl:template>

<xsl:template match="temp"><LI>Temperature <xsl:apply-templates/>&#x00B0;F</LI>

</xsl:template>

<xsl:template match="wind"><LI>Wind: <xsl:apply-templates/>mph</LI>

</xsl:template>

<xsl:template match="text()"><xsl:value-of select="."/>

</xsl:template>

</xsl:stylesheet>

Page 13: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

<weather type="Current conditions"><temp>76</temp><wind>5</wind>

</weather>

<H1>Current conditions</H1>

76

<LI>Temperature: °F</LI>76

<wind>5</wind>

5<LI>Wind: mph</LI>

<temp>76</temp>

5

<HR/>

1

2

3

4

5

6

8

7

9

10

11 1213

XSLT TransformationXSLT Transformation

Page 14: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Demonstration: Demonstration: XSL for DocumentsXSL for Documents Create stylesheet for complex documentCreate stylesheet for complex document Run in browserRun in browser

Page 15: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Demonstration: Demonstration: XSL On The ServerXSL On The Server Get XML document from serverGet XML document from server

Article.xmlArticle.xml Apply stylesheet, transform, and deliver Apply stylesheet, transform, and deliver

HTML to the browserHTML to the browser Article.aspArticle.asp Article.xslArticle.xsl

Page 16: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

XSLT OperationXSLT Operation

XMLXML

XSL (TOC)XSL (TOC) XSL(Abstract)XSL(Abstract) XSL (Full)XSL (Full)

HTML (TOC)HTML (TOC)HTML (Abstract)HTML (Abstract)HTML (Full)HTML (Full)XSL XSL

ProcessorProcessor

(HTML)(HTML)

Page 17: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Demonstration: Demonstration: XML Data IslandsXML Data Islands Create HTML document with XML data Create HTML document with XML data

islandsislands Article.xmlArticle.xml Article-toc.xslArticle-toc.xsl Article-abstract.xslArticle-abstract.xsl Article-full.xslArticle-full.xsl Article-wtoc.xslArticle-wtoc.xsl

Switch stylesheet under script controlSwitch stylesheet under script control ApplyStyle.htmApplyStyle.htm

Page 18: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

Case Study: Case Study: <TAG> Newsletter<TAG> Newsletter

XML-enabled Web SiteXML-enabled Web Sitehttp://tagnewsletter.comhttp://tagnewsletter.com

Page 19: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.

Copyright © 1999, Architag International Corporation.All rights reserved. Use without express written permission from Architag International Corporation is expressly forbidden.

</Tutorial></Tutorial>

Tech Ed 2000 MaterialsTech Ed 2000 Materials http://architag.com/r/TechEd2000http://architag.com/r/TechEd2000

XML and XSLXML and XSL http://msdn.microsoft.com/xmlhttp://msdn.microsoft.com/xml http://www.w3.org/Style/XSL/http://www.w3.org/Style/XSL/

Page 20: Copyright © 1999, Architag International Corporation. All rights reserved. Use without express written permission from Architag International Corporation.