Quiz - XSL and XSLT - XML

  1. Can you arrange the steps in sequence to achieve the processing ?

A.Apply the rules of an XSL stylesheet to document tree.
B.Portion of a tree matching the given pattern is processed by appropriate stylesheet template.
C.XSL processor starts with root node in tree and performs pattern matching.
D.XML processor reads an XML document.
E.XML processor creates a hierarchical tree containing nodes for each piece of information

D - E - A - C - B

  1. Can you match the XSL elements against their corresponding description ?

A.Used to add one sylesheet to another.
xsl:import
B.Allow to set a variable in the XSL file.
xsl:variable
C.Allow the stylesheet to alias one namespace prefix for another in the result tree.
xsl:namespace-alias
D.Used to build templates.
xsl:template
E.Allow stylesheet authors to specify how they wish the result tree to be output.
xsl:output

  1. Which of the statements about CSS and XSL stylesheet languages are true and which statements are false ?

A.CSS uses complex elements to format the documents.
False
B.XSL describes how the XML document should be displayed.
True
C.XSL elements can be used to perform complex calculations.
True
D.XSL is a stylesheet application specifically for HTML
False
E.CSS is a simple,styling-based approach that does not require advanced programming skills.
True

  1. Can you identify the correct code to display the following output ?

                                    (A)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<Article>
            <Date>March 20,2001</Date>
            <Para>
                        The West coast of
                        <Place>Atlanta</Place>
                        some 150 dolphins
            </Para>
</Article>
Style Sheet File
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Article">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Date">
            <xsl:apply-templates />
<xsl:template match="Para">
            <xsl:apply-templates />
</xsl:stylesheet>

                                    (B)  -- Câu B và câu C hoàn toàn giống nhau,thầy nên xem lại --
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>        
<Article>
            <Date>March 20,2001</Date>
            <Para>
                        The West coast of
                        <Place>Atlanta</Place>
                        some 150 dolphins
            </Para>
</Article>

Style Sheet File
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Article">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Date">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Para">
            <xsl:apply-templates />
<xsl:template>
</xsl:stylesheet>
                                    (C)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<Article>
            <Date>March 20,2001</Date>
            <Para>
                        The West coast of
                        <Place>Atlanta</Place>
                        some 150 dolphins
            </Para>
</Article>

Style Sheet File
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Article">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Date">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Para">
            <xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>

                                    (D)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<Article>
            <Date>March 20,2001</Date>
            <Para>
                        The West coast of
                        <Place>Atlanta</Place>
                        some 150 dolphins
            </Para>
</Article>
Style Sheet File
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Article">
            <xsl:apply-templates />
</xsl:template>
<xsl:template match="Date">
<xsl:template match="Para">
            <xsl:apply-templates />
            <xsl:apply-templates />
            </xsl:template>
<xsl:template>
</xsl:stylesheet>


Đáp án C

1.      Can you match the XSL elements against their corresponding description ?

A.Puts a conditional test against the content of the XML file -> xsl:if
B.Add literal text to the output ->xsl:text
C.Extracts the value of a selected node -> xsl:value-of
D.Applies a template repeatedly -> xsl:for-each
E.Inserts a multiple conditional test against the XML file -> xsl:choose

1.      Can you identify the correct code to display the following output? "A. David Blake 18/11/1973"

                                    (A)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<MichiganStaff>
            <Faculty>
                        <Name>David Blake</Name>
                        <DOB>18/11/1973</DOB>
            </Faculty>
</MichiganStaff>

Stylesheet File
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Tranform" version="1.0">
<xsl:template match="/">
            <xsl:for-each select="MichiganStaff/Faculty/Name">
            <xsl:for-each select="MichiganStaff/Faculty">
                        <xsl:number value="position()" sequence="A." />
                        <xsl:value-of select="Name" />
                        <xsl:value-of select="DOB" />
            </xsl:for-each>
</xsl:template>
<xsl:stylesheet>

                                    (B)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<MichiganStaff>
            <Faculty>
                        <Name>David Blake</Name>
                        <DOB>18/11/1973</DOB>
            </Faculty>
</MichiganStaff>

Stylesheet File
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Tranform" version="1.0">
<xsl:template match="/">
            <xsl:for-each select="MichiganStaff/Faculty/Name">
            <xsl:for-each select="MichiganStaff/Faculty/DOB">
                        <xsl:number value="position()" format="A." />
                        <xsl:value-of select="Name" />
                        <xsl:value-of select="DOB" />
            </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

                                    (C)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<MichiganStaff>
            <Faculty>
                        <Name>David Blake</Name>
                        <DOB>18/11/1973</DOB>
            </Faculty>
</MichiganStaff>

Stylesheet File
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Tranform" version="1.0">
<xsl:template match="/">
            <xsl:for-each select="MichiganStaff">
                        <xsl:number value="position()" format="A." />
                        <xsl:value-of select="Name" />
                        <xsl:value-of select="DOB" />
            </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


                                    (D)
XML File
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<MichiganStaff>
            <Faculty>
                        <Name>David Blake</Name>
                        <DOB>18/11/1973</DOB>
            </Faculty>
</MichiganStaff>

Stylesheet File
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Tranform" version="1.0">
<xsl:template match="/">
            <xsl:for-each select="MichiganStaff/Faculty">
                        <xsl:number value="position()" sequence="A." />
                        <xsl:value-of select="Name" />
                        <xsl:value-of select="DOB" />
            </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


2.      Which of these statements about XPath are true and wich of these are false ?

A.XPath provides multiple syntax that can be used for queries, addressing and patterns.
=> False
B.XPath can be thought of as a query language like SQL.
=> True
C.In XPath,the structure of an XML document is viewed conceptually as a pyramid
=> False
D.XPath provides a common syntax for features shared byj XSLT and XQuery.
=>True
E.XPath is used to navigate through elements and attributes in an XML document.
=>True

3.       Can ypu match the XPath nodes against their corresponding desscription ?

A.Has a parent node and it may be the child node too.
=> Text
B.Contains all other nodes in the tree
=> Root
C.Is not considered a child of its parent node because they are not contained in a parent node.
=> Namespace
D.May have a unique identifier associated with them,which is useful when referencing the node with XPath
=> Element
E.Has a parent node that is either an element or root node
=> Attribute

4.      Can you match the diffrent types of matching against their corresponding description ?

A.<xsl:template match="/">......</xsl:template>
 => Matching the root
B.<xsl:template match="Greeting">
 => Matching by name
C.<xsl:template match="P//EM">
 => Matching by ancestry
D.<xsl:template match="Product"> <xsl:apply-templates select="@Unit"> </xsl:template>
=> Matching by attribute
E.<xsl:template match="Product"> <xsl:value-of select="Product_ID"> </xsl:template>
 => Matching the element names

5.      Which of these statements abouts XPath expressions are true and which of these are false ?

A.XSLT allows any kind of data to be transformed into a boolean value.
=> True
B.A node set is an unordered group of nodes from the input document.
=> True
C.A string is an sequence of zero or more Unicode characters.
=> True
D. The numbers like 43 or -7000 that look like integers are stored as float.
=> False
E. A string is a sequence of one or more Unicode characters.
=> False

6.      Which of these statements about XPath functions are true and which of these are false ?

A.The local-name() functions return the name of the current node or the first node in the specified node set - without the namespace prefix.
=> True
B.The floor(num) functions return the largest integer that is not greater than the number argument
=> True
C.The only allowed operation in a result tree fragment is on a number.
=> False
D.In a substring() function,the index of the first charater is 0
=> False
E.The translate() function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string.
=> True

7.      Which of these statements about Switching between styles are true and which and of these are false ?

A. An XSLT processor takes three things as input such as XSLT stylesheet,XML document and Document Type Declaration.
=> False
B. The XSLT engine begins by reading in the XSLT stylesheet and caching it as a look-up table
=> True
C. For each node it processes,it will look in the table for the best matching rule to apply
=> True
D. Starting from the root node,the XSLT engine finds rules,executes them,and continues until there are no more nodes in its context node set to work with
=> True
E. XSLT can also be called as XSLT document or transformation script.
=> False

8.      Can you specify the correct code snippet for transforming the XML document into HTML using XSLT ?

                                    (A)
<?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" />
..........
</xsl:stylesheet>

                                    (B)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:output method="html">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
..................
</xsl:stylesheet>
                                    (C)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
.................
</xsl:template>
</xsl:stylesheet>

                                    (D)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:output method="html" />
..................
<xsl:template match="/">
</xsl:stylesheet>

Share on Google Plus

About Hà Tuấn Anh

0 nhận xét:

Đăng nhận xét