2
我想弄清楚如何使用XSL按字母排序員工的XML列表。現在它只是以與XML中相同的順序顯示XML信息。我不認爲我完全理解如何使用<xsl:sort>
函數,因爲我是XSL的新手。我也嘗試將與<xsl:for-each>
放在一起,我也無法讓它工作。使用XSL按字母順序排序XML節點
繼承人我的xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Company1.xsl"?>
<Company>
<Employee>
<Firstname>John</Firstname>
<Lastname>Smith</Lastname>
<ssn>635-35-7463</ssn>
<doh>February 3, 2011</doh>
<Age>34</Age>
</Employee>
<Employee>
<Firstname>Brad</Firstname>
<Lastname>Roberts</Lastname>
<ssn>789-65-4568</ssn>
<doh>February 13, 2012</doh>
<Age>25</Age>
</Employee>
<Employee>
<Firstname>Karen</Firstname>
<Lastname>Smith</Lastname>
<ssn>369-12-7415</ssn>
<doh>March 24, 2011</doh>
<Age>28</Age>
</Employee>
<Employee>
<Firstname>Eli</Firstname>
<Lastname>Smith</Lastname>
<ssn>489-32-8525</ssn>
<doh>September 14, 2010</doh>
<Age>38</Age>
</Employee>
<Employee>
<Firstname>Bill</Firstname>
<Lastname>Joel</Lastname>
<ssn>689-67-7634</ssn>
<doh>February 29, 2012</doh>
<Age>24</Age>
</Employee>
<Employee>
<Firstname>Kelly</Firstname>
<Lastname>Greene</Lastname>
<ssn>927-82-6873</ssn>
<doh>December 3, 2010</doh>
<Age>34</Age>
</Employee>
</Company>
而且我的繼承人XSL:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Company Employees</TITLE>
</HEAD>
<BODY>
<H2>Company Employees</H2>
<xsl:for-each select="Company/Employee">
<xsl:sort select="Employee/Lastname" data-type="text" order="ascending"/>
<xsl:sort select="Employee/Firstname" data-type="text" order="ascending"/>
<SPAN STYLE="font-weight:bold">FirstName: </SPAN>
<xsl:value-of select="Lastname" />
<BR />
<SPAN STYLE="font-weight:bold">LastName: </SPAN>
<xsl:value-of select="Firstname" />
<BR />
<SPAN STYLE="font-weight:bold">SSN: </SPAN>
<xsl:value-of select="ssn" />
<BR />
<SPAN STYLE="font-weight:bold">Date of Hire: </SPAN>
<xsl:value-of select="doh" />
<BR />
<SPAN STYLE="font-weight:bold">Age: </SPAN>
<xsl:value-of select="Age" />
<P/>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
這做到了!很高興這很簡單。感謝您的快速響應。 – Jmh2013 2012-03-22 02:19:27
@ Fourthmeal70,很高興我能幫上忙。坦率地說,我甚至都不知道你可以用XSLT做多種類型,所以我也學到了一些東西。爲了在將來的問題中獲得最佳結果,您應該將正確答案標記爲「已接受」(複選標記)。 – harpo 2012-03-22 02:34:36