|
|
(10 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{TOCright}}
| + | Has been moved to: http://blog.kr8.de/wiki-xslt/ |
− | Siehe auch: [[kr8lex:XSL|XSLT]]
| |
− | | |
− | Mithilfe von XSL-Stylesheets kann man [[XML]]-Dokumente in verschiedenen Output-Formate '''transformieren'''.
| |
− | | |
− | == Web Links ==
| |
− | * http://www.zvon.org/xxl/XSLTreference/Output/index.html
| |
− | | |
− | == XSL Namespace ==
| |
− | Das XSL-Stylesheet sollte anfangen mit:
| |
− | | |
− | <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
| |
− | | |
− | == XSL Output Methods ==
| |
− | * <xsl:output method = "text" />
| |
− | * <xsl:output method = "html" />
| |
− | * <xsl:output method = "xml" />
| |
− | | |
− | == Ein einfaches Beispiel ==
| |
− | Als Eingabe folgendes XML-Dokument:
| |
− | <pre>
| |
− | <?xml version="1.0" encoding="UTF-8"?>
| |
− | <message>Yep, it worked!</message>
| |
− | </pre>
| |
− | Zur Transformation folgendes XSL-Stylesheet:
| |
− | <pre>
| |
− | <?xml version="1.0" encoding="UTF-8"?>
| |
− | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
| |
− | <xsl:output method="text" encoding="UTF-8"/>
| |
− | <!-- simply copy the message to the result tree -->
| |
− | <xsl:template match="/">
| |
− | <xsl:value-of select="message"/>
| |
− | </xsl:template>
| |
− | </xsl:stylesheet>
| |
− | </pre>
| |
− | | |
− | Der Aufruf eines XSLT-Prozessors erzeut die Ausgabedatei (output-mthod="text"):
| |
− | <pre>
| |
− | Yep, it worked!
| |
− | </pre>
| |
− | | |
− | == XSLT-Prozessoren ==
| |
− | Um aus Eingabe und XSLT-Sheet eine Ausgabe zu erzeugen, benötigen wir einen sog. XSLT-Prozessor. Gängige XSLT-Prozessoren sind u.a.:
| |
− | * [[Xalan]] (Xalan-J)
| |
− | * Apache Xalan C++
| |
− | * SAXON
| |
− | * Sablotron
| |
− | | |
− | == Beispiel Notizbuch ==
| |
− | Mein Outlook-[[Notizbuch]] hatte ich in [[EverNote]] importiert, um daraus ein irgendwie brauchbares XML-Standatdformat zu erzeugen, z.B. [[RSS]] oder [[Atom]]...
| |
− | | |
− | Eingabe ist die mit [[EverNote]] erstellte Datei '''EverNote_v2.xml''':
| |
− | <pre>
| |
− | <evernote>
| |
− | <notes>
| |
− | <note name="title" content_date="2005/03/30 15:30:45" created="2008/04/07 19:55:01" id="[FA1234-5678-45454554]">
| |
− | <content type="html">
| |
− | <div>...html content...</div>
| |
− | </content>
| |
− | <contentplain>
| |
− | ....plain ascii content
| |
− | </contentplain>
| |
− | </note>
| |
− | </notes>
| |
− | </evernote>
| |
− | </pre>
| |
− | | |
− | Zur Transformation in [[Atom]] habe ich das XSL-Sheet '''evernote2atom.xsl''' entwickelt:
| |
− | <pre>
| |
− | <?xml version="1.0" encoding="iso-8859-1"?>
| |
− | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2005/Atom" version="1.0">
| |
− | <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-section-elements="content" />
| |
− | | |
− | <xsl:template match="/EVERNOTE">
| |
− | <xsl:text>
| |
− | </xsl:text><feed>
| |
− | <title>Notizbuch</title>
| |
− | <subtitle>Ehemalige Outlook-Notizen</subtitle>
| |
− | <link href="http://example.org/feed/" rel="self"/>
| |
− | <link href="http://example.org/"/>
| |
− | <xsl:variable name="D" select="@date" />
| |
− | <updated>
| |
− | <xsl:value-of select="concat(substring($D,1,4),'-',substring($D,6,2),'-',substring($D,9,2),'T',substring($D,12,8),'Z')" />
| |
− | </updated>
| |
− | <author>
| |
− | <name>Dietrich Kracht</name>
| |
− | <email>dietrich@kr8.de</email>
| |
− | </author>
| |
− | <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
| |
− | <xsl:apply-templates select="//NOTE"/>
| |
− | </feed>
| |
− | </xsl:template>
| |
− |
| |
− | <xsl:template match="/EVERNOTE/NOTES/NOTE">
| |
− | <entry>
| |
− | <title>
| |
− | <xsl:value-of select="@name"/>
| |
− | </title>
| |
− | <link href="http://localhost/wordpress/?p=33"/>
| |
− | <id>
| |
− | <xsl:value-of select="@id" />
| |
− | </id>
| |
− | <xsl:variable name="C" select="@content_date" />
| |
− | <updated>
| |
− | <xsl:value-of select="concat(substring($C,1,4),'-',substring($C,6,2),'-',substring($C,9,2),'T',substring($C,12,8),'Z')" />
| |
− | </updated>
| |
− | <xsl:variable name="D" select="@created" />
| |
− | <published>
| |
− | <xsl:value-of select="concat(substring($D,1,4),'-',substring($D,6,2),'-',substring($D,9,2),'T',substring($D,12,8),'Z')" />
| |
− | </published>
| |
− | <category term="Notizbuch" />
| |
− | <author>
| |
− | <name>Dietrich Kracht</name>
| |
− | </author>
| |
− | <content type="xhtml">
| |
− | <xsl:value-of select="CONTENT" />
| |
− | </content>
| |
− | <content2>
| |
− | <xsl:value-of select="CONTENTPLAIN"/>
| |
− | </content2>
| |
− | </entry>
| |
− | </xsl:template>
| |
− | </xsl:stylesheet>
| |
− | </pre>
| |
− | | |
− | Aufruf des XSLT-Prozessors [[Xalan]]:
| |
− | <pre>
| |
− | java org.apache.xalan.xslt.Process -IN EverNote_v2.xml -XSL evernote2atom.xsl -OUT NotizbuchAtom.xml
| |
− | </pre>
| |
− | | |
− | Generiert als Ergebnis eine [[Atom]]-Datei:
| |
− | <pre>
| |
− | </pre>
| |
− | | |
− | == Weitere Beispiele ==
| |
− | * [[DocBook]]
| |
− | * [[WebsiteTraditionell]]
| |
− | * [[MediaLibrary]]
| |
− | | |
− | | |
− | | |
− | | |
− | -- [[User:Dkracht|Dkracht]] 13:07, 12 April 2009 (CEST)
| |