Difference between revisions of "XSLT"

From Dietrich Blog (Strato)
Jump to: navigation, search
(XSLT-Prozessoren)
(Replaced content with "Has been moved to: http://blog.kr8.de/wiki-xslt/")
 
Line 1: Line 1:
{{TOCright}}
+
Has been moved to: http://blog.kr8.de/wiki-xslt/
Siehe auch: [[kr8lex:XSL|Lexikon]], [[OxygenXMLEditor]]
 
 
 
Mithilfe von XSL-Stylesheets kann man [[XML]]-Dokumente in verschiedenen Output-Formate '''transformieren'''.
 
 
 
== Anwendungsbeispiele ==
 
* [[Notizbuch]] in [[RSS]]/[[Atom]] transformieren
 
* [[DocBook]]
 
* [[MediaLibrary]] in PDF und in SQL transformieren
 
* [[Rezeptdatenbanken]] in CookML
 
* Teile von [[WebsiteTraditionell]]: [[WebsiteLexikon]], Deskriptoren, MediaLibrary...
 
 
 
== 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]]...
 
 
 
=== Notizbuch Eingabedatei ===
 
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>
 
 
 
=== Notizbuch XSLT-Datei ===
 
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>
 
 
 
=== Notizbuch Aufruf XSLT-Prozessor ===
 
Aufruf des XSLT-Prozessors [[Xalan]]:
 
<pre>
 
java org.apache.xalan.xslt.Process  -IN EverNote_v2.xml -XSL evernote2atom.xsl -OUT NotizbuchAtom.xml
 
</pre>
 
 
 
=== Notizbuch Ausgabedatei ===
 
Generiert als Ergebnis die [[Atom]]-Datei '''NotizbuchAtom.xml''':
 
<pre>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<feed xmlns="http://www.w3.org/2005/Atom">
 
<title>Notizbuch</title>
 
<subtitle>Ehemalige Outlook-Notizen</subtitle>
 
<link rel="self" href="http://example.org/feed/"/>
 
<link href="http://example.org/"/>
 
<updated>2008-03-31T18:56:03Z</updated>
 
<author>
 
<name>Dietrich Kracht</name>
 
<email>dietrich@kr8.de</email>
 
</author>
 
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
 
<entry>
 
<title>Zählspiel nach Stableford</title>
 
<link href="http://localhost/wordpress/?p=33"/>
 
<id>[FA797DE2-6761-4369-B0C5E5FD4B3D1D86]</id>
 
<updated>2005-03-05T22:14:45Z</updated>
 
<published>2008-03-31T16:21:11Z</published>
 
<category term="Notizbuch"/>
 
<author>
 
<name>Dietrich Kracht</name>
 
</author>
 
<content type="xhtml"><![CDATA[<DIV>Zählspiel nach Stableford<br /><br />Vorgabe 0 18 36 54<br />Par 2 3 4 5 <br />1 über Par 1 2 3 4 <br />2 über Par 0 1 2 3<br />3 über Par 0 0 1 2<br />4 über Par 0 0 0 1</DIV>]]>
 
</content>
 
<content2>Zählspiel nach Stableford Vorgabe 0 18 36 54 Par 2 3 4 5 1 über Par 1 2 3 4 2 über Par 0 1 2 3 3 über Par 0 0 1 2 4 über Par 0 0 0 1      Open source Outlook message &gt;&gt;               
 
</content2>
 
</entry>
 
...
 
</feed>
 
</pre>
 
 
 
 
 
 
 
-- [[User:Dkracht|Dkracht]] 13:07, 12 April 2009 (CEST)
 

Latest revision as of 14:05, 19 April 2020

Has been moved to: http://blog.kr8.de/wiki-xslt/