xml - wordpress.comxslt-basic •option 1 •open a note pad •write a xml code and save with .xml...
TRANSCRIPT
XML By B.A. Khivsara
Outline
XML
Internal DTD
External DTD
XSLT
XML- Basics
• Option 1
• Open a note pad
• Write a xml code
• Save with .xml extension
• Double click on file and output will be shown in browser
• Option 2
• Go to Eclipse
• File-> New ->Project ->next -> Give any name to project
• Right click on project Name -> Src ->New -> other -> XML -> xml file -> create XML file from an xml template
XML Example
• <notes> • <note nid="A1"> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • <note nid="A2"> • <to>Amit</to> • <from>Neha</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • </notes>
XML attribute XML Root Element
XML Child Element
Outline
XML
Internal DTD
External DTD
XSLT
Internal DTD -Basic
• Option 1
• Open a note pad
• Write a DTD code in xml file
• Save with .xml extension
• Double click on file and output will be shown in browser
• Option 2
• Go to Eclipse
• File-> New ->Project ->next -> Give any name to project
• Right click on project Name -> Src ->New -> other -> XML -> xml file -> create XML file from an xml template
Internal DTD Example • <?xml version="1.0" encoding="UTF-8"?> • <!DOCTYPE notes [ • <!ELEMENT note (to,from,heading,body)> • <!ELEMENT to (#PCDATA)> • <!ELEMENT from (#PCDATA)> • <!ELEMENT heading (#PCDATA)> • <!ELEMENT body (#PCDATA)> • <!ATTLIST note nid ID #REQUIRED> • ]> • <notes> • <note nid="A1"> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • <note nid="A2"> • <to>Amit</to> • <from>Neha</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • </notes>
To validate code in Eclipse
• Right click in .xml code window
• Click on validate
• If any errors it shows red cross in front of that line
• If now errors shows the message as no compilation errors
Outline
XML
Internal DTD
External DTD
XSLT
External DTD -Basic
• Option 1
• Open a note pad
• Write a XML code and save with .xml extension
• Write a DTD code and save with .dtd extension
• Give reference of .dtd file in .xml file
• Run the .xml file in browser
• Option 2
• Go to Eclipse
• File-> New ->Project ->next -> Give any name to project
• Right click on project Name -> Src ->New -> other -> XML -> xml file -> create XML file from an xml template
• Right click on project Name -> Src ->New -> other -> XML -> DTD File-> Give filename with .dtd extension
External DTD Example .xml File
• <?xml version="1.0" encoding="UTF-8"?>
• <!DOCTYPE note SYSTEM "ExternalDTD.dtd">
• <note>
• <to>Tove</to>
• <from>Jani</from>
• <heading>Reminder</heading>
• <body>Don't forget me this weekend</body>
• <to>Amit</to>
• <from>Neha</from>
• <heading>Reminder</heading>
• <body>Don't forget me this weekend</body>
• </note>
External DTD Example .dtd File
• <?xml version="1.0" encoding="UTF-8"?>
• <!ELEMENT note (to,from,heading,body)+>
• <!ELEMENT to (#PCDATA)>
• <!ELEMENT from (#PCDATA)>
• <!ELEMENT heading (#PCDATA)>
• <!ELEMENT body (#PCDATA)>
To validate code in Eclipse
• Right click in .xml code window
• Click on validate
• If any errors it shows red cross in front of that line
• If now errors shows the message as no compilation errors
Outline
XML
Internal DTD
External DTD
XSLT
XSLT-Basic
• Option 1
• Open a note pad
• Write a XML code and save with .xml extension
• Write a DTD code and save with .xsl extension
• Give reference of .xsl file in .xml file
• Run the .xml file in browser
• Option 2
• Go to Eclipse
• File-> New ->Project ->next -> Give any name to project
• Right click on project Name -> Src ->New -> other -> XML -> xml file -> create XML file from an xml template
• Right click on project Name -> Src ->New -> other -> XML -> XSLT File-> Give filename with .xsl extension
Option 1
• XML Code when want to run on browser
• To Run just double click on .xml file
XSLT - .xml File • <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?> • <Notes> • <note> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • <note> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • <note> • <to>Tove</to> • <from>Jani</from> • <heading>Reminder</heading> • <body>Don't forget me this weekend</body> • </note> • </Notes>
XSLT - .xsl File <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>book</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>To</th> <th>From</th> </tr> <xsl:for-each select="Notes/note"> <tr> <td><xsl:value-of select = "to"/></td> <td><xsl:value-of select = "from"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Option 2
• XML Code when want to run In Eclipse
• To Run steps are shown below
XSLT - .xml File <?xml version="1.0" encoding="UTF-8"?> <Notes> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note> </Notes>
XSLT - .xsl File <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> <body>
<h2>book</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>To</th>
<th>From</th>
</tr>
<xsl:for-each select="Notes/note">
<tr>
<td><xsl:value-of select = "to"/></td>
<td><xsl:value-of select = "from"/></td>
</tr>
</xsl:for-each>
</table>
</body> </html>
</xsl:template>
</xsl:stylesheet>
Right Click on .xml File name
Click on Run Configurations
Click on Out Put tab
Give .html Extension
Right Click on .xsl File name
Click on XSL transformations
Click on Workplace & select .xml file name
Click on .html file
Output of XSLT in HTML format