Top Banner
XML By B.A. Khivsara
27

XML - WordPress.comXSLT-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

Mar 08, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: XML - WordPress.comXSLT-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

XML By B.A. Khivsara

Page 2: XML - WordPress.comXSLT-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

Outline

XML

Internal DTD

External DTD

XSLT

Page 3: XML - WordPress.comXSLT-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

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

Page 4: XML - WordPress.comXSLT-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

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

Page 5: XML - WordPress.comXSLT-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

Outline

XML

Internal DTD

External DTD

XSLT

Page 6: XML - WordPress.comXSLT-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

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

Page 7: XML - WordPress.comXSLT-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

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>

Page 8: XML - WordPress.comXSLT-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

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

Page 9: XML - WordPress.comXSLT-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
Page 10: XML - WordPress.comXSLT-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

Outline

XML

Internal DTD

External DTD

XSLT

Page 11: XML - WordPress.comXSLT-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

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

Page 12: XML - WordPress.comXSLT-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

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>

Page 13: XML - WordPress.comXSLT-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

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)>

Page 14: XML - WordPress.comXSLT-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

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

Page 15: XML - WordPress.comXSLT-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

Outline

XML

Internal DTD

External DTD

XSLT

Page 16: XML - WordPress.comXSLT-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

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

Page 17: XML - WordPress.comXSLT-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

Option 1

• XML Code when want to run on browser

• To Run just double click on .xml file

Page 18: XML - WordPress.comXSLT-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

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>

Page 19: XML - WordPress.comXSLT-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

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>

Page 20: XML - WordPress.comXSLT-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

Option 2

• XML Code when want to run In Eclipse

• To Run steps are shown below

Page 21: XML - WordPress.comXSLT-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

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>

Page 22: XML - WordPress.comXSLT-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

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>

Page 23: XML - WordPress.comXSLT-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

Right Click on .xml File name

Click on Run Configurations

Page 24: XML - WordPress.comXSLT-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

Click on Out Put tab

Give .html Extension

Page 25: XML - WordPress.comXSLT-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

Right Click on .xsl File name

Click on XSL transformations

Page 26: XML - WordPress.comXSLT-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

Click on Workplace & select .xml file name

Page 27: XML - WordPress.comXSLT-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

Click on .html file

Output of XSLT in HTML format