1 / 21

Databases and Information Systems 1

Databases and Information Systems 1. Transformation of XML Documents. TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A. XSLT. Extensible Stylesheet Language (XSL) Extensible Stylesheet Language Transformations (XSLT). XML. XML Document. (X)HTML.

asasia
Télécharger la présentation

Databases and Information Systems 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DatabasesandInformation Systems 1 Transformation of XML Documents TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A

  2. XSLT • Extensible Stylesheet Language (XSL) • Extensible StylesheetLanguage Transformations (XSLT) XML XML Document (X)HTML XSLT Processor XSL Stylesheet Text

  3. Obtaining an XSLT IDE • XML Cooktop • http://www.xmlcooktop.com/

  4. XML- and XSL-Examples (1)

  5. XML and XSL Examples(2)

  6. XSL defaulttemplates 1/2 • Default template for elements and root: <xsl:templatematch = "*|/"> <xsl:apply-templates/></xsl:template> • Default template for text nodes and attributes: <xsl:templatematch="text()|@*"> <xsl:value-ofselect="."/> </xsl:template>

  7. XSL defaulttemplates 2/2 • Default templateforcommentsandprocessinginstructions: <xsl:templatematch="comment()|processing-instruction()"></xsl:template> • defaultbehaviourfornamespacenodesdo not outputnamespacenodes

  8. ProcessingModel <xsl:templatematch="/DB"> <xsl:apply-templatesselect="order"/> </xsl:template> <xsl:templatematch="order"> <xsl:value-ofselect="@ID"/> <xsl:apply-templatesselect="*"/> </xsl:template> <xsl:templatematch="customer|PC"> <xsl:value-ofselect="."/> </xsl:template> <xsl:templatematch="/ | ∗"> <xsl:apply-templates/> </xsl:template> / DB order order custo-mer PC PC custo-mer Node list: <order, order> <customer, PC> <order> <PC> <root> <customer, PC> <PC> Output: 23 Meier Pc500 24 Reich pc600

  9. Template Match v’ P v = actual node • Whendoes a templatematch? • Letv betheactualcontextnode. LetPbe an XPathexpressionwithinthematchattributeofthe tag <xsl:templates> • Pmatches,itexists an ancestornodev’(v=v’ ok), so thatvistheresultofevaluatingPwiththeactualnodev’.

  10. XML and XSL Examples (3)

  11. XML and XSL Examples (4)

  12. XML and XSL Examples (5)

  13. HTML file and HTML output <html> <body> <table width="100%" border="1"> <tr> <td>customer: </td><td>PC : </td> </tr> <tr> <td>Meier</td><td>pc500</td> </tr> <tr> <td>Reich</td><td>pc600</td> </tr> </table> </body> </html>

  14. XSLT stylesheet and HTML output first Template <html> <body> <table width="100%" border="1"> <tr> <td>customer: </td><td> PC : </td> </tr> start here for every customer node repeat <tr> <td>Name of customer</td><td>PC</td> </tr> until here for every customer node </table> </body> </html> separate template

  15. XSLT stylesheet and HTML output

  16. XPath location expressions in XSL Application in XSL:XPath location expression <xsl:template match="Auftrag"> <xsl:value-of select="PC"> <xsl:if test='position()&gt;1'>...</xsl:if> </xsl:template> XPath Boolean expression

  17. More locationexpressions (examples) • locationexpression in XSL: „outputattributesize“ • <xsl:value-ofselect="@size"/> • XPath Boolean expressions „ifattribute type hasthevalueCHAR , output ... “ • <xsl:iftest="@type='CHAR'„> (<xsl:value-ofselect="@size"/>)</xsl:if> • „ifcurrentis not firstwithinparent (position >1):“ • <xsl:iftest='position() &gt; 1'> not thefirst</xsl:if>

  18. CurrentNode ContextNode • current() returns a node-set that contains only the currentnode. • Usually the currentnodeand the contextnode (.) are the same. • But… Current node Context node

  19. Generating an SQL script file with XSLT <xsl:template match="/"> create table order( customer char(10) , PC char(10) ) ; <xsl:apply-templates/> </xsl:template> <xsl:template match=„order"> insert into order values( <xsl:value-of select=„customer"/> , <xsl:value-of select="PC"/> ) ; </xsl:template> XSLT DB

  20. Advantages of XML and XSL • Generate HTML on a web server: • transform: data.xml + layout.xsl -> x.html • XML istransformableby different XSL filestogenerateappropriateoutputfor different destinationformats, e.g. html , pdf , txt, …

  21. Summary • Database  XML  PDF or HTML or TXT or XML or… • Database  XML  SQL  Database DB XSLT Original database DB Other database

More Related