tailieunhanh - Pro PHP XML and Web Services phần 5

định nghĩa các biểu thức để kiểm tra bằng cách sử dụng thuộc tính kiểm tra. Đây là giống như các thuộc tính thử nghiệm trên các xsl: nếu phần tử. Khi đánh giá là TRUE, nội dung của nguyên tố này là khởi tạo, nếu không, xsl tiếp theo khi một phần tử được thử nghiệm. Nếu tất cả các bài kiểm tra từ xsl | 360 CHAPTER 10 EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS XSLT defines the expression to test using the test attribute. This is the same as the test attribute on the xsl if element. When it evaluates to TRUE the content of the element is instantiated otherwise the next xsl when element is tested. If all the tests from the xsl when elements fail the content from the xsl otherwise element if present is instantiated. For example xsl template match sites site xsl choose xsl when test @num 1 xsl value-of select . url xsl when xsl when test @num 3 Site Number 3 xsl when xsl otherwise No matching Sites xsl otherwise xsl choose xsl template This template tests the num attribute of the current site element in context. When using the following XML data with a style sheet containing the template xml version encoding iso-8859-1 sites site num 1 name PHP name url http url site site num 2 name XML C Parser name url http url site sites the resulting tree from the template would be as follows http No matching Sites Sorting You can sort node sets within an xsl apply-templates or xsl for-each element using an xsl sort element. When used within an xsl for-each element it must be the first child element but may come after an xsl param element within the contents of an xsl apply-templates element CHAPTER 10 EXTENSIBLE STYLESHEET LANGUAGE TRANSFORMATIONS XSLT 361 xsl sort select string-expression lang nmtoken data-type text number qname-but-not-ncname order ascending descending case-order upper-first lower-first This element specifies the sort key for the node set from the parent element. You can use multiple xsl sort elements to create sort keys which are then processed in order. The sort key is created based on the resulting string from the expression defined in the select attribute. When not present the select attribute defaults to . causing the text value of the current node to be used as the sort key. For example xsl for-each select .