[ Pobierz całość w formacie PDF ]
.you would set theletter-valueattribute to the keyword alphabetic.The keyword otherspecifiesa numeric sequence.For example,Group Separator AttributesIn the United States, we tend to write large numbers with commas grouping everythree digits like 4,567,302,000.However, in many languages and countries, a periodor a space separates the groups instead; for instance, 4.567.302.000 or 4 567 302000.Furthermore, in some countries it s customary to group large numbers everyfour digits instead of every three; for example, 4,5673,0000.If you re dealing withvery long lists that may contain a thousand or more items, you need to worry aboutthese issues.The digit-group-sepattribute specifies the grouping separator used betweengroups of digits.The n-digits-per-groupattribute specifies the number of digitsused in a group.Generally, you d make these attributes contingent on the language.For example,The sequence-src AttributeFinally, if you want to use an unusual order (for example, a list of date strings like1-1-1999, 1-2-1999, 1-3-1999,.or a list that jumps by tens like 10, 20, 30, 40,.) youcan store this list (separated by whitespace) in a separate document.Thesequence-srcattribute has a value representing the relative or absolute URL ofthis document.For example,Sorting Output ElementsThe xsl:sortelement sorts the output elements into a different order than theyappear in the input.An xsl:sortelement appears as a child of an xsl:apply-3236-7 ch14.F.qc 6/30/99 2:42 PM Page 495Chapter 14 &' XSL Transformations495templateselement or xsl:for-eachelement.The selectattribute of the xsl:sortelement defines the key used to sort the elements output by xsl:apply-templatesor xsl:for-each.By default, sorting is performed in alphabetical order of the keys.If more than onexsl:sortelement is present in a given xsl:apply-templatesor xsl:for-eachelement, then the output sorts first by the first key, then by the second key, and soon.If any elements still compare equally, they output in the order they appear inthe source document.For example, suppose you have a file full of ATOMelements arranged alphabetically.To sort by atomic number, you can use the style sheet in Listing 14-18.Listing 14-18: An XSL style sheet that sorts by atomic numberAtomic Number vs.Atomic WeightAtomic Number vs.Atomic WeightElementAtomic NumberAtomic Weight3236-7 ch14.F.qc 6/30/99 2:42 PM Page 496Part III &' Style Languages496Figure 14-5 shows the results that display the limits of alphabetical sorting.Hydrogen,atomic number 1, is the first element.However, the second element is not helium,atomic number 2, but rather neon, atomic number 10.Although 10 sorts after 9numerically, alphabetically 10 falls before 2.Figure 14-5: Atoms alphabetically sorted by atomic numberYou can, however, adjust the order of the sort by setting the optional data-typeattribute to the value number.For example,Figure 14-6 shows the elements sorted properly.You can change the order of the sort from the default ascending order to descend-ing by setting the orderattribute to descendinglike this:This sorts the elements from the largest atomic number to the smallest so thathydrogen now appears last in the list.3236-7 ch14.F.qc 6/30/99 2:42 PM Page 497Chapter 14 &' XSL Transformations497Figure 14-6: Atoms numerically sorted by atomic numberAlphabetical sorting naturally depends on the alphabet.The langattribute can setthe language of the keys.The value of this attribute should be an ISO 639 languagecode like enfor English.Cross- These are the same values supported by the xml:lang attribute discussed inReferenceChapter 10, Attribute Declarations in DTDs.Finally, you can set the case-orderattribute to one of the two values upper-firstor lower-firstto specify whether uppercase letters sort before lowercaseletters or vice versa.The default depends on the language.CDATA and
[ Pobierz całość w formacie PDF ]