XML文件
public class PlacesListExperienceCartItem {
@Id
String id;
String customerId;
String placeId;
Double totalPrice;
List<PlacesExperienceCartConfirmRequest> experienceList;
private String bookingId;
private String name;
private String phone;
private String email;
private Location deliveryLocation;
private List<String> selectedDates;
public List<String> getSelectedDates() {
return selectedDates;
}
public void setSelectedDates(List<String> selectedDates) {
this.selectedDates = selectedDates;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPlaceId() {
return placeId;
}
public void setPlaceId(String placeId) {
this.placeId = placeId;
}
public Double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(Double totalPrice) {
this.totalPrice = totalPrice;
}
public List<PlacesExperienceCartConfirmRequest> getExperienceList() {
return experienceList;
}
public void setExperienceList(List<PlacesExperienceCartConfirmRequest> experienceList) {
this.experienceList = experienceList;
}
public String getBookingId() {
return bookingId;
}
public void setBookingId(String bookingId) {
this.bookingId = bookingId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Location getDeliveryLocation() {
return deliveryLocation;
}
public void setDeliveryLocation(Location deliveryLocation) {
this.deliveryLocation = deliveryLocation;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
}
XSL文件
<?xml version="1.0"?>
<books>
<book>
<title fiction="true">Happy Potter</title>
<author>J. K. Rowling et al</author>
<price>29.99</price>
</book>
<book>
<title fiction="true">The Hobbit</title>
<author>J.R.R. Tolkien</author>
<price>25.99</price>
</book>
<book>
<title fiction="true">Greater than 30</title>
<author>J.R.R. Tolkien</author>
<price>31.99</price>
</book>
<book>
<title fiction="false">Non-Fiction</title>
<author>J.R.R. Tolkien</author>
<price>19.99</price>
</book>
所以我的XSL将根据给定的条件从XML中提取数据。
当<xsl:for-each select="books/book">
<xsl:if test="(title[@fiction='false']) and (price < 30)">
<span name="title"><xsl:value-of select="title"/></span><br/>
<span name="author"><xsl:value-of select="author"/></span><br/>
<span name="price"><xsl:value-of select="price"/></span><br/><br/>
</xsl:if>
</xsl:for-each>
Total: <span name="total"><xsl:value-of select="sum(books/book/price)"/></span>
和fiction=true
时。但我不知道如何总和总价值。任何建议将不胜感激。
答案 0 :(得分:0)
使用谓词sum(books/book[title[@fiction='false'] and price < 30]/price)
。
你也可以缩短
<xsl:for-each select="books/book">
<xsl:if test="(title[@fiction='false']) and (price < 30)">
到
<xsl:for-each select="books/book[title[@fiction='false'] and price < 30]">