Simple Example: use XML Schema + XSL + XML to create a resume

Source: Internet
Author: User
Tags xsl file

XML series: the example uses XML Schema + XSL + XML to create a resume.

The following is a simple resume created using XML Schema + XSL + XML. Through this example, we hope that you can understand XML schema, XSL, and XML in a more practical way.

1. Create the XML schema file resume. XSD

<? XML version = "1.0" encoding = "gb2312"?>
<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" elementformdefault = "qualified" attributeformdefault = "unqualified">
 <! -- Basic Information -->
<Xs: element name = "name" type = "XS: string"/>
<Xs: element name = "gender">
<Xs: simpletype>
<Xs: Restriction base = "XS: string">
<Xs: enumeration value = "male"/>
<Xs: enumeration value = ""/>
</Xs: Restriction>
</Xs: simpletype>
</Xs: Element>
<Xs: element name = "" type = "XS: string"/>
<Xs: element name = "Date of Birth">
<Xs: simpletype>
<Xs: Restriction base = "XS: Date">
<Xs: min‑sive value = "1970-01-01"/>
<Xs: maxcompute sive value = "1990-01-01"/>
</Xs: Restriction>
</Xs: simpletype>
</Xs: Element>
<Xs: element name = "Marital Status">
<Xs: simpletype>
<Xs: Restriction base = "XS: string">
<Xs: enumeration value = "married"/>
<Xs: enumeration value = "Unmarried"/>
</Xs: Restriction>
</Xs: simpletype>
</Xs: Element>
<Xs: element name = "health condition" type = "XS: string"/>
<Xs: element name = "education" type = "XS: string"/>
<Xs: element name = "Graduate School" type = "XS: string"/>
<Xs: element name = "" type = "XS: string"/>
<Xs: element name = "contact number" type = "XS: string"/>
<Xs: element name = "contact address" type = "XS: string"/>
<Xs: element name = "email" type = "XS: string"/>
<Xs: group name = "baseinfogroup">
<Xs: sequence>
<Xs: Element ref = "name"/>
<Xs: Element ref = "gender"/>
<Xs: Element ref = "nationality"/>
<Xs: Element ref = "Date of Birth"/>
<Xs: Element ref = "Marital Status"/>
<Xs: Element ref = "Health Status"/>
<Xs: Element ref = "education level"/>
<Xs: Element ref = "Graduate School"/>
<Xs: Element ref = "working years"/>
<Xs: Element ref = "contact number"/>
<Xs: Element ref = "contact address"/>
<Xs: Element ref = "email"/>
</Xs: sequence>
</Xs: group>
<Xs: complextype name = "baseinfotype">
<Xs: group ref = "baseinfogroup"/>
</Xs: complextype>
<Xs: element name = "Basic Information" type = "baseinfotype"/>
<! -- Educational experience -->
<Xs: element name = "Start Time" type = "XS: Date"/>
<Xs: element name = "End Time" type = "XS: Date"/>
<Xs: element name = "school name" type = "XS: string"/>
<Xs: element name = "professional" type = "XS: string"/>
<Xs: group name = "educategroup">
<Xs: sequence>
<Xs: Element ref = "Start Time"/>
<Xs: Element ref = "End Time"/>
<Xs: Element ref = "school name"/>
<Xs: Element ref = "professional"/>
<Xs: Element ref = "education level"/>
</Xs: sequence>
</Xs: group>
<Xs: complextype name = "educatetype">
<Xs: sequence>
<Xs: group ref = "educategroup"/>
</Xs: sequence>
</Xs: complextype>
<Xs: element name = "educational experience" type = "educatetype"/>
<Xs: element name = "education">
<Xs: complextype>
<Xs: sequence maxoccurs = "unbounded">
<Xs: Element ref = "educational experience"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
<! -- Work Experience -->
<Xs: element name = "company name" type = "XS: string"/>
<Xs: element name = "position" type = "XS: string"/>
<Xs: element name = "job description" type = "XS: string"/>
<Xs: group name = "jobgroup">
<Xs: sequence>
<Xs: Element ref = "Start Time"/>
<Xs: Element ref = "End Time"/>
<Xs: Element ref = "company name"/>
<Xs: Element ref = "position"/>
<Xs: Element ref = "job description"/>
</Xs: sequence>
</Xs: group>
<Xs: complextype name = "jobtype">
<Xs: sequence>
<Xs: group ref = "jobgroup"/>
</Xs: sequence>
</Xs: complextype>
<Xs: element name = "work experience" type = "jobtype"/>
<Xs: element name = "work">
<Xs: complextype>
<Xs: sequence maxoccurs = "unbounded">
<Xs: Element ref = "work experience"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
<! -- Self-evaluation -->
<Xs: element name = "self-evaluation" type = "XS: string"/>
<Xs: group name = "resumegroup">
<Xs: sequence>
<Xs: Element ref = "Basic Information"/>
<Xs: Element ref = "education"/>
<Xs: Element ref = "work"/>
<Xs: Element ref = "self-evaluation"/>
</Xs: sequence>
</Xs: group>
<Xs: attribute name = "ID">
<Xs: simpletype>
<Xs: Restriction base = "XS: integer">
<Xs: Pattern value = "[0-9] [0-9] [0-9] [0-9] [0-9]"/>
</Xs: Restriction>
</Xs: simpletype>
</Xs: attribute>
<Xs: complextype name = "resumetype">
<Xs: sequence>
<Xs: group ref = "resumegroup"/>
</Xs: sequence>
<Xs: attribute ref = "ID"/>
</Xs: complextype>
<Xs: element name = "resume" type = "resumetype"/>
<Xs: element name = "resume">
<Xs: complextype>
<Xs: sequence maxoccurs = "unbounded">
<Xs: Element ref = "resume"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
</Xs: schema>

2. Create the XML file resume. xml

<? XML version = "1.0" encoding = "gb2312"?>
<? XML-stylesheet type = "text/XSL" href = "resume. XSL"?>
<Resume xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: nonamespaceschemalocation = "resume. XSD">
<Resume id = "00001">
<Basic info>
<Name> XXX </Name>
<Gender> male </gender>
<Nationality> jingshan, Hubei Province </nationality>
<Date of Birth> 1985-10-17 </Date of Birth>
<Marital status> unmarried </marital status>
<Health status> good <Education level> bachelor degree </education level>
<Graduation school> XXXX Emy-han </graduation school>
<Working life> XXXX </working life>
<Contact number> 13647231773 </contact number>
<Contact address> xxxxxx, Hubei Province </contact address>
<Email> qfs_v@qq.com </Email>
</Basic information>
<Education>
<Educational experience>
<Start time> 200x-09-01 </start time>
<End Time> 200x-09-01 </End Time>
<School Name> XXXX University </School Name>
<Major> Computer Science and Technology </major>
<Education level> bachelor degree </education level>
</Educational experience>
<Educational experience>
<Start time> 200x-08-15 </start time>
<End Time> 200x-08-01 </End Time>
<School Name> xxxxxxx </School Name>
<Professional> XXXX </professional>
<Education level> XXXX </education level>
</Educational experience>
</Education>
<Work>
<Work experience>
<Start time> 200x-03-15 </start time>
<End Time> 200x-05-01 </End Time>
<Company Name> Wuhan XX software Co., Ltd. </Company Name>
<Position> XXX programmer </position>
<Job description> Java programmer
</Job description>
</Work experience>
<Work experience>
<Start time> 200x-06-15 </start time>
<End Time> 200x-05-01 </End Time>
<Company Name> Wuhan XX Technology Co., Ltd. </Company Name>
<Position> Java programmer </position>
<Job description> Java programmer
</Job description>
</Work experience>
</Work>
<Self-evaluation> self-evaluation
</Self-evaluation>
</Resume>
</Resume>

3. Create the XSL file resume. XSL

<? XML version = "1.0" encoding = "gb2312"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform" xmlns: fo = "http://www.w3.org/1999/XSL/Format">
<! -- Root template -->
<XSL: template match = "/">
<HTML>
<Head>
<Title> <XSL: value-of select = "resume/basic info/Name"/> resume </title>
</Head>
<Body>
<H2 align = "center"> resume </H2>
<XSL: Apply-templates select = "resume"/>
</Body>
</Html>
</XSL: Template>
<! -- Resume template -->
<XSL: template match = "resume">
<XSL: Apply-templates select = "resume"/>
</XSL: Template>
<! -- Resume template -->
<XSL: template match = "resume">
<XSL: Apply-templates select = "Basic Information"/>
<Br/>
<XSL: Apply-templates select = "education"/>
<Br/>
<XSL: Apply-templates select = "work"/>
<Br/>
<XSL: Apply-templates select = "self-evaluation"/>
</XSL: Template>
 
<! -- Basic Information Template -->
<XSL: template match = "Basic Information">
<Table align = "center" width = "800" border = "0">
<Tbody>
<Tr>
<TH colspan = "7" bgcolor = "# cae1ff" align = "Left"> Basic Information </Th>
</Tr>
<Tr>
<TD width = "35"> name: </TD>
<TD width = "50"> <XSL: value-of select = "name"/> </TD>
<TD width = "35"> Gender: </TD>
<TD width = "40"> <XSL: value-of select = "gender"/> </TD>
<TD width = "35"> Nationality: </TD>
<TD width = "80"> <XSL: value-of select = ""/> </TD>
<TD width = "150"> photo </TD>
</Tr>
<Tr>
<TD> Date of Birth: </TD>
<TD> <XSL: value-of select = "Date of Birth"/> </TD>
<TD> Marital status: </TD>
<TD> <XSL: value-of select = "Marital Status"/> </TD>
<TD> health status: </TD>
<TD> <XSL: value-of select = "health condition"/> </TD>
</Tr>
<Tr>
<TD> education level: </TD>
<TD> <XSL: value-of select = "education"/> </TD>
<TD> service life: </TD>
<TD> <XSL: value-of select = ""/> </TD>
<TD> graduation School: </TD>
<TD> <XSL: value-of select = "Graduate School"/> </TD>
</Tr>
<Tr>
<TD> contact number: </TD>
<TD> <XSL: value-of select = "contact number"/> </TD>
<TD> Email: </TD>
<TD> <XSL: value-of select = "email"/> </TD>
<TD> contact address: </TD>
<TD> <XSL: value-of select = "contact address"/> </TD>
</Tr>
</Tbody>
</Table>
</XSL: Template>
<! -- Education template -->
<XSL: template match = "education">
<Table width = "800" align = "center">
<Tbody>
<Tr>
<TH colspan = "5" bgcolor = "# cae1ff" align = "Left"> educational experience </Th>
</Tr>
<Tr>
<TD> Start time </TD>
<TD> end time </TD>
<TD> school name </TD>
<TD> major </TD>
<TD> education level </TD>
</Tr>
<XSL: Apply-templates select = "educational experience"/>
</Tbody>
</Table>
</XSL: Template>
 <! -- Educational experience template -->
<XSL: template match = "educational experience">
<Tr>
<TD> <XSL: value-of select = "Start Time"/> </TD>
<TD> <XSL: value-of select = "End Time"/> </TD>
<TD> <XSL: value-of select = "school name"/> </TD>
<TD> <XSL: value-of select = "professional"/> </TD>
<TD> <XSL: value-of select = "education"/> </TD>
</Tr>
</XSL: Template>
 <! -- Work template -->
<XSL: template match = "work">
<Table width = "800" align = "center">
<Tbody>
<Tr>
<TH colspan = "5" bgcolor = "# cae1ff" align = "Left"> Work Experience </Th>
</Tr>
<Tr>
<TD> Start time </TD>
<TD> end time </TD>
<TD> company name </TD>
<TD> position </TD>
<TD> job description </TD>
</Tr>
<XSL: Apply-templates select = "work experience"/>
</Tbody>
</Table>
</XSL: Template>
<! -- Work experience template -->
<XSL: template match = "work experience">
<Tr>
<TD> <XSL: value-of select = "Start Time"/> </TD>
<TD> <XSL: value-of select = "End Time"/> </TD>
<TD> <XSL: value-of select = "company name"/> </TD>
<TD> <XSL: value-of select = ""/> </TD>
<TD width = "350"> <XSL: value-of select = "job description"/> </TD>
</Tr>
</XSL: Template>
<! -- Self-evaluation template -->
<XSL: template match = "self-evaluation">
<Table width = "800" align = "center">
<Tbody>
<Tr>
<TH bgcolor = "# cae1ff" align = "Left"> self-evaluation </Th>
</Tr>
<Tr>
<TD> <XSL: value-of select = "."/> </TD>
</Tr>
</Tbody>
</Table>
</XSL: Template>
</XSL: stylesheet>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.