Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML II: XSL,XPath,XSLT

Similar presentations


Presentation on theme: "XML II: XSL,XPath,XSLT"— Presentation transcript:

1 XML II: XSL,XPath,XSLT http://www.w3.org/ http://www-106.ibm.com/developerworks/ http://www.alphaworks.ibm.com/xml http://www.oasis-open.org/cover/ http://www.topxml.com/ http://www.aifb.uni-karlsruhe.de/~mer/xml.html http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/ http://www.w3schools.com/xml/ http://www.xml.com/

2 Nachtrag Parsen mit SAX Customer X unknown 098 Item 1 32.01 4093 Item 2 0.76 543 Item 3 1.42

3 Handler I … public class MyHandler extends DefaultHandler { private Stack tagStack = new Stack(); private Vector items = new Vector(); private String customer; private CharArrayWriter contents = new CharArrayWriter(); public void startElement( String namespaceURI, String localName, String qName, Attributes attr ) throws SAXException { contents.reset(); tagStack.push( localName ); System.out.println( "path found: [" + getTagPath() + "]" ); }

4 Handler II public void endElement( String namespaceURI, String localName, String qName ) throws SAXException { if ( getTagPath().equals( "/CustomerOrder/Customer/Name" ) ) { customer = contents.toString().trim(); } else if ( getTagPath().equals( "/CustomerOrder/Items/Item/Name" ) ) { items.addElement( contents.toString().trim() ); } // clean up the stack... tagStack.pop(); } public void characters( char[] ch, int start, int length ) throws SAXException { contents.write( ch, start, length ); }

5 XML Baum FileCab This chapter describes the commands that manage the FileCab inet application.

6 Knoten Node Type:Inhalt RootWurzel Element ElementElement Knoten TextText zwischen den Tags AttributeAttribut Knoten NamespaceURI des Namensraums Processing instruction Inhalt der PI, CommentThe text of the comment,

7 XSL XML-Processor java: XALAN c: XP XSLT XSL XSLT Formating Objects XPath

8 XPath I Axis:Selects From: ancestor The parent of the context node, the parent of the parent of the context node, the parent of the parent of the parent of the context node, and so forth back to the root node ancestor-or-self The ancestors of the context node and the context node itself attribute The attributes of the context node child The immediate children of the context node descendant The children of the context node, the children of the children of the context node, and so forth descendant-or-self The context node itself and its descendants following All nodes that start after the end of the context node, excluding attribute and namespace nodes following-sibling All nodes that start after the end of the context node and have the same parent as the context node namespace The namespace of the context node parent The unique parent node of the context node preceding All nodes that finish before the beginning of the context node, excluding attribute and namespace nodes preceding-sibling All nodes that start before the beginning of the context node and have the same parent as the context node self The context node.self::node()..parent::node() namechild::name @nameattribute::name ///descendant-or- self::node()/

9 XPath Funktionen Function:Return Type: Returns: position()numberThe position of the context node in the context node list; the first node in the list has position 1 last()numberThe number of nodes in the context node list; this is the same as the position of the last node in the list count(node-set)numberThe number of nodes in node-set. id(string1 string2 string3…)node setA node set containing all the elements anywhere in the same document that have an ID named in the argument list; the empty set if no element has the specified ID. key(string name, Object value)node setA node set containing all nodes in this document that have a key with the specified value. Keys are set with the top-level xsl:key element. document(string URI, string base) node setA node set in the document referred to by the URI; the nodes are chosen from the named anchor or XPointer used by the URI. If there is no named anchor or XPointer, then the root element of the named document is the node set. Relative URIs are relative to the base URI given in the second argument. If the second argument is omitted, then relative URIs are relative to the URI of the style sheet (not the source document!). local-name(node set)stringThe local name (everything after the namespace prefix) of the first node in the node set argument; can be used without any arguments to get the local name of the context node. namespace-uri(node set)stringThe URI of the namespace of the first node in the node set; can be used without any arguments to get the URI of the namespace of the context node; returns an empty string if the node is not in a namespace. name(node set)stringThe qualified name (both prefix and local part) of the first node in the node set argument; can be used without an argument to get the qualified name of the context node. generate-id(node set)stringA unique identifier for the first node in the argument node set; can be used without any argument to generate an ID for the context node.

10 XPath String Funktionen Function:Return Type: Returns: starts-with(main_string, prefix_string) Boolean True if main_string starts with prefix_string ; false otherwise contains(containing_string, contained_string) Boolean True if the contained_string is part of the containing_string ; false otherwise substring(string, offset, length) String length characters from the specified offset in string ; or all characters from the offset to the end of the string if length is omitted; length and offset are rounded to the nearest integer if necessary substring-before(string, marker-string) String The part of the string from the first character up to (but not including) the first occurrence of marker- string substring-after(string, marker-string) String The part of the string from the end of the first occurrence of marker-string to the end of string ; the first character in the string is at offset 1 string-length(string) Number The number of characters in string normalize-space(string) String The string after leading and trailing white space is stripped and runs of white space are replaced with a single space; if the argument is omitted the string value of the context node is normalized translate(string, replaced_text, replacement_text) String Returns string with occurrences of characters in replaced_text replaced by the corresponding characters from replacement_text concat(string1, string2,... ) StringReturns the concatenation of as many strings as are passed as arguments in the order they were passed format-number(number, format-string, locale-string) String Returns the string form of number formatted according to the specified format-string as if by Java 1.1's java.text.DecimalFormat class (see http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html ); the locale-string is an optional argument that provides the name of the xsl:decimal-format element used to interpret the format-string

11 XSL Verarbeitung

12 Tom Wolfe One beer more 60 Fr.- XSL Processor One beer more

13 xsl Befehle http://www.ibiblio.org/xml/books/bible2/chapters/ch17.html,

14 Beispiel Legi XML Daten Burkhart Helmar 63 Informatik 70-061-634

15 XSL I UNIBS DataBase Studierenden-Datenbank der Uni Basel    Name:    Vorname: …

16 XSL II Informationstag für Maturandinnen und Maturanden an der Universität Basel, 11. Januar 2002

17 HTML

18 Links automatisch generieren Then with expanded wings he steers his flight "Incumbent on the Dusky Air" Aloft, incumbent on the dusky Air That felt unusual weight, till on dry Land "He Lights" He lights, if it were Land that ever burned With solid, as the Lake with liquid fire "The Lake with Liquid Fire"

19 XSL Pictures:

20 XSL II

21 HTML I Pictures: "Incumbent on the Dusky Air" "He Lights" "The Lake with Liquid Fire" Then with expanded wings he steers his flight "Incumbent on the Dusky Air" Aloft, incumbent on the dusky Air

22 HTML II That felt unusual weight, till on dry Land "He Lights" He lights, if it were Land that ever burned With solid, as the Lake with liquid fire "The Lake with Liquid Fire"

23 Xalan set JAVA_HOME=C:\Programme\jbuilder5\jdk1.3 set _CLASSES="C:\xml\xalan-j_2_2_D14\bin\xalan.jar;C:\xml\xerces- 1_4_4\xerces.jar" %JAVA_HOME%\bin\java -cp %_CLASSES% org.apache.xalan.xslt.Process -IN buch.xml -XSL newid.xsl -OUT chapter.html

24 Glossar JAXP Java API for XML Parsing JAXP von java.sun.com definiert eine allgemeine Schnittstelle zur Verarbeitung von XML- Dokumenten, indem es eine weitere Schicht über die vorhandenen APIs ( DOM und SAX ) legt. Zusätzlich wird auch für XSLT-Verarbietung ein herstellerunabhängiges API realisiert. Die einzelnen Implementierungen von DOM - und SAX -Parsern bieten unterschiedliche Schnittstellenfunktionen, bzw. unterschiedliche Ausprägungen an. Schwerwiegender noch definiert die XSLT-Recommendation des W3C lediglich die Sprache und nicht wie diese implementiert werden soll. Für XSLT existiert bislang noch kein API. Von Anwendungsprogrammen können lediglich die unterschiedlichen XSLT-Prozessoren aufgerufen werden. bietet damit erstmals eine einheitliche Schnittstelle für die Verarbeitung von XSLT auf Java-Seite an. ….

25 HTML

26 A, B, C, … Glossar zu XML und XML-basierten Spezifikationen  Das Glossar befindet sich noch im Aufbau. #     [ Index ]

27 Formatierung Eintrag I Top   Index

28 Formatierung Eintrag II   #  


Download ppt "XML II: XSL,XPath,XSLT"

Similar presentations


Ads by Google