Technologie XML
Agenda
2008-03-16 Mgr inż. Michał Jaros 2
• XML + CSS• XPath• XSLT• Podsumowanie• Q&A
Technologie XML
XML + CSSCascading Style Sheets(Kaskadowy Arkusz Styli)
CSS pozwala na definiowanie sposobu wyświetlania elementów strony HTML lub elementów pliku XML.
2008-03-16 Mgr inż. Michał Jaros 3
Technologie XML
XML + CSSSkładnia arkusza styli:
/* komentarz */specyfikator {
/* kolejny komentarz */właściwość: wartość;
}
2008-03-16 Mgr inż. Michał Jaros 4
Technologie XML
XML + CSS• specyfikator = nazwa tagu XML• właściwość
– display:• none• block ≈ <DIV>• inline ≈ <SPAN>• list-item ≈ <LI>• table ≈ <TABLE>• table-row ≈ <TR>• table-cell ≈ <TD>
– margin2008-03-16 Mgr inż. Michał Jaros 5
Technologie XML
XML + CSS
<?xml-stylesheet
href="nazwa_pliku.css”
type="text/css”
?>
/* przykład */
2008-03-16 Mgr inż. Michał Jaros 6
Technologie XML
XPathXPath jest to język służący do odnajdywania
informacji wewnątrz plików XML.
XPath stanowi podstawę dla technologii:• XSLT;• XQuery;• XPointer;• XLink;
2008-03-16 Mgr inż. Michał Jaros 7
Technologie XML
XPathSłowniczek
• Węzeł – dokument, element, atrybut;• Rodzic;• Dzieci;• Rodzeństwo;• Przodek;• Potomek;
2008-03-16 Mgr inż. Michał Jaros 8
<bookstore><book lang="en”>
<title>Harry Potter</title><author>J K. Rowling</author><year>2005</year><price>29.99</price>
</book></bookstore>
Technologie XML
XPathXPath – ścieżka do danych
• nazwa_węzła– bookstore
• /– /bookstore– bookstore/book
• //– //book– bookstore//book
2008-03-16 Mgr inż. Michał Jaros 9
Technologie XML
XPath• []
– /bookstore/book[1]– /bookstore/book[last()-1]– /bookstore/book[position() < 4]– //book[@lang]– //book[@lang=‘en’]– /bookstore/book[price < 30.00]/title
2008-03-16 Mgr inż. Michał Jaros 11
Technologie XML
XPath• *
– /bookstore/*– //*
• @*– //book/@*
• node()– //book/node()
2008-03-16 Mgr inż. Michał Jaros 12
Technologie XML
XPath• |
– //book/title | //book/price– //title | //price– /bookstore/book/title | //price
2008-03-16 Mgr inż. Michał Jaros 13
Technologie XML
XML – przestrzenie nazw<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/"><h:tr>
<h:td>Apples</h:td><h:td>Bananas</h:td>
</h:tr></h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture"><f:name>African Coffee Table</f:name><f:width>80</f:width><f:length>120</f:length>
</f:table></root>
2008-03-16 Mgr inż. Michał Jaros 14
Technologie XML
XSLTEXtensible Stylesheet Language Transformations
XSLT – język przekształcający XML’a do XHTML’a lub innego XML’a.
Wsparcie przeglądarek:• Mozilla Firefox – v 1.0.2• Netscape – v 8• Opera – v 9• Internet Explorer – v 6
2008-03-16 Mgr inż. Michał Jaros 15
Technologie XML
XSLTDodanie XSLT do pliku XML
<?xml-stylesheet
href="nazwa_pliku.xsl”
type="text/xsl”
?>Główny element (korzeń) pliku XSL
<xsl:stylesheetversion="1.0”xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>2008-03-16 Mgr inż. Michał Jaros 16
Technologie XML
XSLT<xsl:template match="wyrażenie XPath">
<!-- strona (X)HTML -->
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
Treść strony
</body>
</html>
</xsl:template>
2008-03-16 Mgr inż. Michał Jaros 17
Technologie XML
XSLT• <xsl:value-of select="wyrażenie XPath" />
• <xsl:for-each select="wyrażenie XPath"><!-- instrukcje -->
</xsl:for-each>
• <xsl:sort select="wyrażenie XPath" />
• <xsl:if test="wyrażenie"><!-- instrukcje -->
</xsl:if>
2008-03-16 Mgr inż. Michał Jaros 18
Technologie XML
XSLT• <xsl:choose>
<xsl:when test="wyrażenie"><!-- instrukcje -->
</xsl:when><xsl:otherwise>
<!-- instrukcje --></xsl:otherwise>
</xsl:choose>
2008-03-16 Mgr inż. Michał Jaros 19
Technologie XML
XSLT• <xsl:apply-templates />• <xsl:apply-templates select="wyrażenie XPath" />
2008-03-16 Mgr inż. Michał Jaros 20
<xsl:template match="/"><html>
<body><h2>My CD Collection</h2> <xsl:apply-templates/>
</body></html>
</xsl:template>
<xsl:template match="cd"><p><xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/></p></xsl:template>
Technologie XML
XLinkxmlns:xlink="http://www.w3.org/1999/xlink"
<tag_link
xlink:type="simple“
xlink:href=“http://jakis.adres"
xlink:show="new">
Wyświetlany tekst linka
</tag_link>
2008-03-16 Mgr inż. Michał Jaros 21
Technologie XML
Podsumowanie• XML + CSS• XPath• XSLT• http://www.w3schools.com
2008-03-16 Mgr inż. Michał Jaros 22
Top Related