• Need help with an XML assignment

    From The Doctor@21:1/5 to All on Wed Sep 2 16:44:55 2015
    All right

    The objective are:

    Welcome to the final lesson and project for your Introduction to XML course! When beginning any XML project, remember that XML and XSL are flexible technologies. There are lots of different ways to structure your data in XML, just as there are many
    different ways to create the same document using XSL. As an XML programmer, you'll want to make your XML and XSL as clear as possible for humans to understand. Choose your elements and attributes carefully, and craft a master layout for your documents.
    This layout will be protected by your schemas, and your XML files will be made more useful through translations to HTML, XML, or other types of files. Have fun with this final project!
    Personal Information Manager

    Throughout the course lessons, you learned how to use XML and XSL to create meaningful applications. Now you're ready to create your final XML application of: a personal information manager, or PIM.

    A PIM keeps track of your contact information in an clear, manageable format. Typical entries include:

    First Name
    Last Name
    Home Phone
    Work Phone
    Cell Phone
    Address
    Email Address

    Depending on your data, there may be many more or slightly different entries. For your final project, you'll define a format for your PIM information to be stored in XML. You'll create XSL documents to translate your source XML into HTML, and create a
    schema.
    Storing the Data in XML

    The first task at hand is to define how your information will be stored. Your project will need to contain at least seven defined elements and three attributes. Start the project by defining your schema. Your schema must be as specific as possible to
    strictly enforce your specifications. Be sure to use appropriate data types.

    It's up to you to define your own XML markup for your PIM. Make sure your tags can be understood clearly by others! Also, be sure to validate your XML document against your schema—you don't want to turn in an invalid XML phonebook!
    Output to HTML

    If you maintain your own website, you'll find this part of the final project especially useful. You're going to use your knowledge of HTML, XML, and XSL to create an XSL 2.0 file to generate two meaningful HTML representations of your phonebook.

    You're required to use a table for your objective—so you'll likely have to use the xsl:for-each construct.

    You also need to demonstrate your knowledge of XPath and XSLT 2.0 features.

    That's it. After your final project is complete, you'll have demonstrated your knowledge of XML and XSL. Save your files as an enduring testament to your knowledge and expertise. Then go forth and create XML and XSL with confidence!



    So far I have

    employees.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <?xml-stylesheet type="text/xsl" href="Employees.xsl" ?>

    <!DOCTYPE Employees>
    <Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Employees.xsd">
    <Employee>
    <FirstName>John</FirstName>
    <LastName>Smith</LastName>
    <Phone Type="Home">1-800-123-4567</Phone>
    <Phone Type="Work">1-800-343-0123</Phone>
    <Phone Type="Cell">1-800-234-5678</Phone>
    <Address>123 street Anytown AS 12345</Address>
    <EmailAddress>johnsmith@company.com</EmailAddress>
    </Employee>

    <Employee >
    <FirstName>Jane</FirstName>
    <LastName>Jones</LastName>
    <Phone Type="Home">na</Phone >
    <Phone Type="Work">1-800-343-0124</Phone>
    <Phone Type="Cell">1-800-999-9999</Phone>
    <Address>123 Avenue Anytown AS 23456</Address>
    <EmailAddress>janejones@company.com</EmailAddress>
    </Employee>

    <Employee >
    <FirstName>Sally</FirstName>
    <LastName>Evans</LastName>
    <Phone Type="Home">1-800-323-1230</Phone>
    <Phone Type="Work">1-800-343-0125</Phone>
    <Phone Type="Cell">1-800-989-0000</Phone>
    <Address>123 Blvd Anytown AS 23451</Address>
    <EmailAddress>sallyevans@company.com</EmailAddress>
    </Employee>

    <Employee >
    <FirstName>Jas</FirstName>
    <LastName>Singh</LastName>
    <Phone Type="Home">1-800-423-1234</Phone>
    <Phone Type="Work">1-800-343-0126</Phone>
    <Phone Type="Cell">1-800-989-0044</Phone>
    <Address>123 Road Anytown AS 23451</Address>
    <EmailAddress>jassingh@company.com</EmailAddress>
    </Employee>

    </Employees>

    Employees.xsd

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Employees">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" name="Employee"/>
    <xs:element name="Employee">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="1" maxOccurs="unbounded" name="FirstName"/>

    <xs:element minOccurs="1" maxOccurs="unbounded" name="LastName"/>

    <xs:element minOccurs="1" maxOccurs="unbounded" name="Phone"/>

    <xs:element minOccurs="1" maxOccurs="unbounded" name="Address"/>

    <xs:element minOccurs="1" maxOccurs="unbounded" name="EmailAddress"/>

    </xs:sequence>
    </xs:complexType>
    </xs:sequence>
    </xs:complexType>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>


    </xs:schema>

    and Employees.xsl

    <?xml version="1.0" ?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">




    <xsl:for-each select="/Employees/Employee/FirstName">
    First Name: <xsl:value-of select="."/> &#xD;
    Last Name: <xsl:value-of select="../LastName"/> &#xD;
    <xsl:for-each select="/Employees/Employee/Phone/@Type">
    <xsl:value-of select="/Employees/Employee/Phone/@Type"/> Phone: <xsl:value-of select="/Employees/Employee/Phone" /> &#xD;
    </xsl:for-each>

    Address: <xsl:value-of select="../Address" /> &#xD;
    EmailAddress: <xsl:value-of select="../EmailAddress" /> &#xD;
    </xsl:for-each>

    <xs:complexType name="PhoneType">
    <xs:simpleContent>
    <xs:extension base="xs:token">
    <xs:attribute name="Type" type="PhoneServiceType" use="required"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>


    <xs:simpleType name="PhoneServiceType">
    <xs:restriction base="xs:token">
    <xs:enumeration value="Home"/>
    <xs:enumeration value="Work"/>
    <xs:enumeration value="Cell"/>
    <xs:enumeration value="Fax"/>
    </xs:restriction>
    </xs:simpleType>

    </xsl:template>


    </xsl:stylesheet>

    Translating the XML file, I get

    First Name: John Last Name: SmithHome Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-
    800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567 Address: 123 street Anytown AS 12345 EmailAddress: johnsmith@company.com First Name: Jane Last Name: JonesHome Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home
    Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-
    4567 Address: 123 Avenue Anytown AS 23456 EmailAddress: janejones@company.com First Name: Sally Last Name: EvansHome Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone:
    1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567 Address: 123 Blvd Anytown AS 23451 EmailAddress: sallyevans@company.com First Name:
    Jas Last Name: SinghHome Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-
    4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567Home Phone: 1-800-123-4567 Address: 123 Road Anytown AS 23451 EmailAddress: jassingh@company.com

    What am I doing wrong?



    --
    Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca
    God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism
    Time for Stephen to move on on Oct 19 2015!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Tobin@21:1/5 to The Doctor on Wed Sep 2 20:31:39 2015
    In article <ms7927$5d$1@ns2.nl2k.ab.ca>,
    The Doctor <doctor@doctor.nl2k.ab.ca> wrote:

    <xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes" />

    You say you're generating HTML, but you don't output any HTML elements,
    just text.

    <xsl:for-each select="/Employees/Employee/FirstName">

    Do you really want to loop over employee first names, rather than
    employees? According to the schema, they might have several first
    names each.

    First Name: <xsl:value-of select="."/> &#xD;

    &#xD; is carriage return. If you're generating HTML you don't need to
    worry about the details of line breaks.

    You seem to have a bunch of schema stuff in your stylesheet
    that was presumably meant to be in the schema.

    -- Richard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to Richard Tobin on Fri Sep 11 02:21:01 2015
    In article <ms7mbb$rp6$2@macpro.inf.ed.ac.uk>,
    Richard Tobin <richard@cogsci.ed.ac.uk> wrote:
    In article <ms7927$5d$1@ns2.nl2k.ab.ca>,
    The Doctor <doctor@doctor.nl2k.ab.ca> wrote:

    <xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes" />

    You say you're generating HTML, but you don't output any HTML elements,
    just text.

    <xsl:for-each select="/Employees/Employee/FirstName">

    Do you really want to loop over employee first names, rather than
    employees? According to the schema, they might have several first
    names each.

    First Name: <xsl:value-of select="."/> &#xD;

    &#xD; is carriage return. If you're generating HTML you don't need to
    worry about the details of line breaks.

    You seem to have a bunch of schema stuff in your stylesheet
    that was presumably meant to be in the schema.

    -- Richard

    Just debug why when it transfer to html is chokes.
    --
    Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca
    God,Queen and country!Never Satan President Republic!Beware AntiChrist rising! http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism
    Time for Stephen to move on on Oct 19 2015!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)