我有一个xml文件,我绑定到xsd架构。我想以这样的方式为模式创建一个xsl,无论我在其中编写xml的顺序是按顺序打印出来的 例如:
'<employee>
<firstname>sultan</firstname>
<lastname>saadat</lastname>
</employee>'
如果上面的块是这样写的:
<employee>
<lastname>saadat</lastname>
<firstname>sultan</firstname>
</employee>
转换时它应该以相同的方式出现而不是解析它的方式?可能的解决方案是什么?
此xml文件出现问题
<?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>
一个部分的样本样式表,其他部分也是如此:
<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>
答案 0 :(得分:1)
有许多方法,但它们倾向于按顺序循环遍历“姓氏或名字”的标签。一个例子是
<xsl:for-each select="firstname|lastname">
<xsl:value-of select=".">
</xsl:for-each>