xslt cookbook phần 5

Những bộ phải được bình đẳng khi các bản sao được bỏ qua. Bạn cũng phải làm nhiều hơn so với loại bỏ phần tử đầu tiên trên bước đệ quy, bạn nên loại bỏ tất cả các phần tử có giá trị như các yếu tố đầu tiên, cũng giống như bạn làm cho các thiết lập thứ hai. | xsl call-template name vset equal-text-values xsl with-param name nodes1 select nodes1 not . nodes1 1 xsl with-param name nodes2 select nodes2 not . nodes1 1 xsl call-template xsl when xsl otherwise xsl choose xsl template Notice that we have commented out the test for unequal sizes because that test is not valid in the presence of duplicates. For example one set might have three occurrences of an element with string value foo while the other has a single element foo. These sets should be equal when duplicates are ignored. You also must do more than remove just the first element on the recursive step you should remove all elements with the same value as the first element just as you do for the second set. This will ensure that duplicates are fully accounted for on each recursive pass. These changes make all equality tests based on text value come out correct but at the cost of doing additional work on sets that are obviously unequal. These equality tests are not as general as the value-set operations produced in Recipe because they presume that the only notion of equality you care about is text-value equality. You can generalize them by reusing the same technique you used for testing membership based on a test of element equality that can be overridden by an importing stylesheet xsl template name vset equal xsl param name nodes1 select . xsl param name nodes2 select . xsl if test count nodes1 count nodes2 xsl call-template name vset equal-impl xsl with-param name nodes1 select nodes1 xsl with-param name nodes2 select nodes2 xsl call-template xsl if xsl template -- Once we know the sets have the same number of elements -- -- we only need to test that every member of the first set is -- -- a member of the second -- xsl template name vset equal- impl xsl param name nodes1 select . xsl param name nodes2 select . xsl choose xsl when test not nodes1 xsl value-of select true xsl when xsl otherwise xsl variable name test xsl apply-templates select nodes2 mode vset .

TÀI LIỆU XEM NHIỀU
TỪ KHÓA LIÊN QUAN