header1.html

Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Sunday, 20 July 2014

What is XSLT?How to Transform XML data using XSLT?

In this post we are going to discuss about-How we can display XML content?There are multiple ways to do to so,but XSLT is best suitable way.So,what is XSLT?

To know about XSLT: Extensible Stylesheet Language Transformation, we should have the basic idea of following,

What is a Markup Language?

A language specially designed for processing, defining and presenting text/data is called a Markup Language.

To know about XSLT, we should have the basic idea of following.

There are three languages in XSL family,

  1. XSL Transformations(XSLT): XML language for transforming XML Documents.
  2. XSl  Formatting Objects (XSL-FO):XML language for specifying the visual formatting of an XML document.
  3. XML Path Language (XPATH): a non XML language used by XSLT, and also available for use in non-XSLT contexts, for addressing the parts on an XML document.

  • XSLT helps to transform one XML document to another. Output of XSL transformation can be another XML, HTML or PDF. Data from one XML can be read and modified into another applying arithmetic, numeric, string operations based on the need.
  • XSLT was developed by W3C especially for XML. XSLT internally uses XPATH and XSL-FO for navigating, performing calculation and for formatting the data.
  • XSLT documents are well-formed XML documents that describe how another XML document should be transformed. For XSLT to work, it needs an XML document to transform and an engine to make the transformation take place. In addition, parameters can be passed in to XSLTs providing further instructions on how to do the transformation.
Why and where is it used?

In web application, web services sent the business data in form of XML within the Applications and across the applications. Since XML is accepted as the most common mode of storing and passing data, a language is needed to read the XML in different ways for different application.


A medium like XSLT is needed to parse the data from XML and give it to browsers to render the HTML code. XSLT works in between XML and Browser to transform the data.


Example:

Blog.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="BlogsStyle.xsl"?>
<Blogs>
       <name id="21">
                <bname>Career Web Helper</bname>
                <Topics>Online Quizzes,MCQs and Articles on Microsoft Technologies.</Topics>
       </name>
                   <place>Pune</place>
                   <language>English</language>
</Blogs>

BlogsStyle.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="Blogs">
<html>
<body>
   <h2>Blog Detail</h2>
   <table border="1">
     <tr>
       <td bgcolor="gray">Blog Id</td>
       <td><xsl:value-of select="name/@id"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Blog Name</td>
       <td><xsl:value-of select="name/bname"/></td>
     </tr>
      <tr>
       <td bgcolor="gray">Topics Covered</td>
       <td><xsl:value-of select="name/Topics"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Place</td>
       <td><xsl:value-of select="place"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Language</td>
       <td><xsl:value-of select="language"/></td>
     </tr>
   </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output:

Sample Basic XSLT Example

This is only basic of XSLT,we will cover some advance topics in upcoming posts. Hope you like this post. 


Sunday, 30 June 2013

XML Multiple Choice Questions(MCQs)


1.Which of the following is correct way to link XSLT to XML?
A.<?xml-stylesheet type="stylesheet" href="MyXSLT.xsl"?>
B.<?xml-stylesheet type="text/xsl" href="MyXSLT.xsl"?>
A.Both A&B
B.None of A&B
C.Only A
D.Only B
Click for answer 

D.Only B
2.XML tags should be in Lower case.True/False?
A.True
B.False
Click for answer 

B.False
3.Which one is correct ?
A.There is no requirement for an XML document to be valid in order to have an information set.
B.An XML document has an information set if it is well-formed
Click for answer 

B.An XML document has an information set if it is well-formed.
4.XML attributes must be quoted.True or False?
A.False
B.True
Click for answer 

B.True
5.Which of the following is valid xml element name?
A.<xmldocument>
B.<7table>
C.<$date>
D.<TableElement>
Click for answer 

D.<TableElement>
6.The following XML will work properly?
<birth date="30/06/2013">
MyBirthDate </Tempbirth> </birth>
A.Yes
B.No
Click for answer 

B.No;Tags are not well formed.
7.<birth date=30/06/2013>
MyBirthDate </birth>.Is this XML Tag is in Correct format?
A.No;attribute is not quoted
B.Yes
Click for answer 

A.No;attribute is not quoted
8.State True/False? "Main purpose of XML is to remove HTML."
A.False
B.True
Click for answer 

A.False

Thursday, 2 May 2013

XML Quiz-3


XML Quiz-3
1.Text inside a CDATA section will be parsed by the parser.
True
False


2.Writing an Internal DTD inside a DOCTYPE is known as:
Declaration
Wrapping
Sequencing
None of above


3.Logical structure of data can be interpreted and used in many ways by various applications due to XML
True
False


4.It is possible to have a property with multiple values
True
False


5.A CDATA section ends with _____.
!>
>
]]>
None of above


6.XML documents should not contain non ASCII characters.True or False?
True
False


7.The XML DOM defines a standard way for accessing and manipulating XML documents.True or False?
True
False


8.What is used to avoid element name conflicts in XML?
DTD
XML Namespaces
Schema
None of above


9.Which attribute is used to define namespace in XML document?
xmlns
ns
resource
using


10.XML specification states that a program should not stop processing an XML document if it finds an error.
True
False

XML Quiz-2


XML Quiz-2
1.XML element's attributes are different from HTML attributes.True or False?
True
False


2."XML Attributes Must be Quoted".True or False?
True
False


3."XML attributes cannot contain multiple values but elements can." True or False?
True
False


4."XML attributes can contain tree structures". True or False?
True
False


5. What do you mean by "Well Formed" XML?
XML validated against a DTD
XML with correct syntax
XML document having a root element
None of above


6. What do you mean by "Valid" XML?
XML document having a root element
XML with correct syntax
XML validated against a DTD
None of above


7."XML documents must have a root element".True or False?
True
False


8.XML documents carry information about how to display the data.True or False?
True
False


9.With XSLT you can transform an XML document into HTML.True or False?
True
False


10.XML tags are case sensitive.True or False?
True
False

XML MCQs Quiz-1


XML Quiz-1
1.Which of the following is correct regarding Embedded Simple Types representing date and time in XML Schema?
xs:date
xs:gMonthYear
xs:timeDate
xs:gDayMonth


2. XML is designed to transport and store data.True or False?
True
False


3.XML is a software- and hardware dependent tool for carrying information.
True
False


4.XML data is stored in....format.
Binary
Unicode
Text
None of these


5.Which of the following is an API for accessing XML documents?
SAX
SOAP
XPath
None of above


6. XML Tags are Case Sensitive.True or False?
True
False


7.<!-- This is a comment --!> is comment in XML.True or False?
True
False


8..Net class for validate xml document?
XmlRangeValidator
RangeValidator
XmlValidatingReader
None of these


9.XML Document can be seen through:
XML Document
XML Source
Transform Source
None of these


10.XML Names can contain letters, numbers, and other characters
True
False