1 / 35

Oblig 2: The Candy-community.

Oblig 2: The Candy-community. Om XML, XSLT, Sablotron og HTML. Oblig 2: Prototype. Begrenset prototype Teste teknologi: XML, XSLT, Sablotron, HTML Velge og illustrere metadata: Interessant for deres prosjekt Interessant for sosial navigasjon. Argumentere for valg og design.

alida
Download Presentation

Oblig 2: The Candy-community.

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. Oblig 2: The Candy-community. Om XML, XSLT, Sablotron og HTML.

  2. Oblig 2: Prototype • Begrenset prototype • Teste teknologi: • XML, XSLT, Sablotron, HTML • Velge og illustrere metadata: • Interessant for deres prosjekt • Interessant for sosial navigasjon. • Argumentere for valg og design.

  3. Oblig 2: Grovstruktur • Definer et format og metadata. • Lag en falsk databasefil i XML. • Gjør tre utdrag fra ”databasen” • Transformer utdragene til tre HTML-filer.

  4. Oblig 2: Mulig sekvens

  5. The Candy Community • Fiktivt community • Godteri-relatert og sukkersøt musikk. • To typer metadata: • Candy factor • Sugar level

  6. Candy: XML-”database” <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6" sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> <songcandyfactor="3" sugarlevel="high"> <title>Sugar Baby Love</title> <artist>The Rubettes</artist> </song> <songcandyfactor="2" sugarlevel="low"> <title>Honey</title> <artist>Tori Amos</artist> </song> <songcandyfactor="5" sugarlevel="low"> <title>Sweet</title> <artist>JR Ewing</artist> </song> <songcandyfactor="0" sugarlevel="low"> <title>Bittersweet symphony</title> <artist>The Verve</artist> </song> </songs>

  7. Candy: XML-”database” <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6“ sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> … </songs>

  8. Candy: XML-Prolog <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6“ sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> … </songs> Meta-informasjon, XML-versjon og enkoding.

  9. Candy: Toppnivå-elementet <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6“ sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> … </songs> XML kan ha ett og bare ett toppnivå-element

  10. Candy: Song-elementet <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6“ sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> … </songs> Flere song-elementer, metadata som attributter.

  11. Candy:Data-elementer <?xmlversion="1.0" encoding="UTF-8"?> <songscommunity="candy"> <songcandyfactor="6“ sugarlevel="medium"> <title>Freia gele</title> <artist>The Jelloes</artist> </song> … </songs> Metadata som elementer.

  12. XSLT • eXtensible Style sheet Language: Transformations • Forvandle XML til annen XML, HTML eller tekst. • Opererer på en logisk trestruktur. • Noder, rot, stier, akser, osv.

  13. XPath • Språk for å angi stier og utdrag fra et XML (DOM)-tre. • Brukes i XSLT og XQuery. • Innebygde funksjoner og akser. • Meget ekspressivt.

  14. Candy: Trestruktur

  15. Candy: Utdrag med XSLT • Sangens tittel • Candyfactor • Sortert • Omdøpe candyfactor • <xsl:something/> angir XSLT-instruksjoner • Alt annet er ”utskrift” til skjerm

  16. Candy: Stilarket <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> </xsl:stylesheet>

  17. Candy: Stilarket <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> … </xsl:template> </xsl:stylesheet>

  18. Stilarket: Prolog <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> … </xsl:template> </xsl:stylesheet>

  19. Stilarket: Meta-info <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> … </xsl:template> </xsl:stylesheet> Informasjon om stilarket, XSLT-versjon og namespace.

  20. Stilarket: Output-metode <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> … </xsl:template> </xsl:stylesheet> Informasjon om resultatet av transformasjonen.

  21. Stilarket: Maler <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheetversion="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outputmethod="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:templatematch="/songs"> … </xsl:template> </xsl:stylesheet> Mal for å håndtere elementer fra match.

  22. Candy: Trestruktur

  23. Stilarket: Songs-malen <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template>

  24. Stilarket: Nytt topp-element <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> Opprette nytt toppnivå-element.

  25. Stilarket: Iterasjon over noder <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> Itererer over song-noder som er barn av songs.

  26. Candy: Trestruktur

  27. Stilarket: Sortering av noder <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> Sortering basert på en nøkkel, stigende eller synkende.

  28. Stilarket: Nytt song-element <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> Opprette flere song-elementer.

  29. Stilarket: XPath-kortform <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> XPath-uttrykk i {…}

  30. Stilarket: Tekstverdi av noder <xsl:templatematch="/songs"> <songs> <xsl:for-eachselect="song"> <xsl:sortselect="@candyfactor" order="descending"/> <songcandy="{@candyfactor}"> <xsl:value-ofselect="title"/> </song> </xsl:for-each> </songs> </xsl:template> Hente verdien av alle tekstnoder av valgte node.

  31. Sablotron • XSLT-prosessor for kommandolinjen • Linux: /store/opt/sablotron/bin/sabcmd • sabcmd <stilark> <xml-fil> <output-fil> • sabcmd lagxml.xsl candy.xml candy2.xml

  32. Candy: Utdraget <?xmlversion="1.0" encoding="UTF-8"?> <songs> <songcandy="6">Freia gele</song> <songcandy="5">Sweet</song> <songcandy="3">Sugar Baby Love</song> <songcandy="2">Honey</song> <songcandy="0">Bittersweet symphony</song> </songs>

  33. Bruk av XSLT i eksemplet • <xsl:stylesheet version=”[versjon av XSLT]” xmlns:xsl:=”[URL til namespace]”/> • <xsl:template select=”[XPath-uttrykk]”/> • <xsl:for-each select=”[XPath-uttrykk]”/> • <xsl:sort select=”[XPath-uttrykk]” order=”[stigende/økende]”/> • <xsl:value-of select=”[XPath-uttrykk]”/> • Les mer i spesifikasjonen

  34. Noen muligheter i XSLT/XPath • Flere maler. • Navngitte maler. • Import/include. • Variabler og parametere. • Parse eksterne dokumenter. • Avanserte XPath-uttrykk. • If-else/for each/select case. • +++

  35. Ressurser • http://www.w3.org/TR/xslt • http://www.w3.org/TR/xpath • http://www.w3.org/TR/REC-xml/ • http://zvon.org/xxl/XSLTreference/Output/index.html

More Related