Reputation: 2278
I've an xml file which i have bound to an xsd schema. I want to create an xsl for the schema in such a way that whatever order i write the xml in it comes printed out in that order for example:
'<employee>
<firstname>sultan</firstname>
<lastname>saadat</lastname>
</employee>'
If the above block is written like this:
<employee>
<lastname>saadat</lastname>
<firstname>sultan</firstname>
</employee>
It should come out in the same way when transformed and not in the wayy it is parsed? what could be the possible solutions?
having trouble with this xml file
<?xml version="1.0" encoding="UTF-8"?>
<resume>
<professional-experience-section>
<section-name>PROFESSIONAL EXPERIENCE</section-name>
<enabled>true</enabled>
<company>
<name>Computer Sciences Corporation</name>
<city>New York</city>
<state>NY</state>
<country>United States</country>
<job-title>
<title>Senior Software Engineer</title>
<start-date>Aug 1996</start-date>
<end-date>May 2010</end-date>
<ongoing>false</ongoing>
<job-description>
<bullet-point>
<statement>C#, Visual Basic, Asp.net</statement>
</bullet-point>
<bullet-point>
<statement>Inspect completed work to ensure conformance to specifications, standards, and contract requirements.</statement>
</bullet-point>
<bullet-point>
<statement>Another Work Description.</statement>
</bullet-point>
</job-description>
</job-title>
</company>
<company>
<name>Acme</name>
<city>Silver Spring</city>
<state>MD</state>
<country>United States</country>
</company>
</professional-experience-section>
<education-section>
<section-name>EDUCATION</section-name>
<enabled>true</enabled>
<institution>
<name>Allston Community College</name>
<city>Akron</city>
<state>MA</state>
<country>United States</country>
<degree>Bachelor of Art in Marketing Candidate</degree>
<end-date>Jan 2020</end-date>
<ongoing>true</ongoing>
<expected-completion-date>Jan 2020</expected-completion-date>
<completed></completed>
<bullet-point>
<statement>detail of what i did at the allston community college</statement>
</bullet-point>
</institution>
</education-section>
<additional-skills-section>
<section-name>ADDITIONAL SKILLS</section-name>
<enabled>true</enabled>
<layout>1 Column</layout>
<bullet-point>
<statement>1</statement>
</bullet-point>
</additional-skills-section>
<custom-section>
<section-name>PUBLICATIONS</section-name>
<layout>2</layout>
<bullet-point>
<statement>test</statement>
</bullet-point>
</custom-section>
<custom-section>
<section-name>AWARDS</section-name>
<layout>2</layout>
<bullet-point>
<statement>test</statement>
</bullet-point>
</custom-section>
</resume>
Sample Stylesheet for one section, same goes for other sections:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/resume">
<xsl:value-of select="/resume/contact-information/full-name"/>
<xsl:value-of select="/resume/contact-information/address_line_1"/>
<xsl:value-of select="/resume/contact-information/address_line_2"/>
<xsl:value-of select="/resume/contact-information/city"/>
<xsl:value-of select="/resume/contact-information/state"/>
<xsl:value-of select="/resume/contact-information/country"/>
<xsl:value-of select="/resume/contact-information/phone"/>
<xsl:for-each select="/resume/professional-experience-section/company">
<!--for company name-->
<xsl:value-of select="name"/>
<xsl:value-of select="city"/>, <xsl:value-of select="state"/>
<xsl:value-of select="country"/>
<!--loop into job title-->
<xsl:for-each select="job-title">
<!--for job title-->
<xsl:value-of select="title"/>
<!--for job start date and job end date-->
<xsl:value-of select="start-date"/> – <xsl:value-of
select="end-date"/>
<!--Loop into job description-->
<xsl:for-each select="job-description">
<!--loop into each bullet point-->
<xsl:for-each select="bullet-point">
<xsl:value-of select="statement"/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
Upvotes: 1
Views: 1211
Reputation: 65116
There's many ways, but they tend to boil down to looping through tags that are "either lastname or firstname" in order. One example would be
<xsl:for-each select="firstname|lastname">
<xsl:value-of select=".">
</xsl:for-each>
Upvotes: 1