这可能是最简单的解决方案之一(根本没有显式条件,所有输出仅由身份模板生成):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"property
[not(contains('|unit|apartment|',
concat('|',type,'|')
)
)
or
not(numberOfBedrooms > 1)
]
"/>
</xsl:stylesheet>
当应用于此 XML 文档时(提供的 - 更正和放大):
<rentalProperties>
<property available="yes" contact="0423020892">
<type>house</type>
<price>800</price>
<address>
<streetNo>116</streetNo>
<street>Warrigal Road</street>
<suburb>Camberwell</suburb>
<state>VIC</state>
<zipcode>3124</zipcode>
</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="0423020899">
<type>apartment</type>
<price>500</price>
<address>
<streetNo>116</streetNo>
<street>Water St.</street>
<suburb>Hornsby</suburb>
<state>NSW</state>
<zipcode>2012</zipcode>
</address>
<numberOfBedrooms>2</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="0423011111">
<type>unit</type>
<price>800</price>
<address>
<streetNo>7</streetNo>
<street>Ryan St</street>
<suburb>Isacs</suburb>
<state>ACT</state>
<zipcode>2603</zipcode>
</address>
<numberOfBedrooms>1</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
<property available="yes" contact="04231234567">
<type>hotel</type>
<price>1200</price>
<address>
<streetNo>4</streetNo>
<street>Bench St.</street>
<suburb>Deakin</suburb>
<state>ACT</state>
<zipcode>2600</zipcode>
</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
</rentalProperties>
产生想要的正确结果(只输出满足所有约束的属性之一):
<rentalProperties>
<property available="yes" contact="0423020899">
<type>apartment</type>
<price>500</price>
<address>
<streetNo>116</streetNo>
<street>Water St.</street>
<suburb>Hornsby</suburb>
<state>NSW</state>
<zipcode>2012</zipcode>
</address>
<numberOfBedrooms>2</numberOfBedrooms>
<description>Ideal for the familly is this charming Californian Bungalow. Comprising a spacious living area, formal dining room plus a huge family/meals area, bright modern well appointed kitchen with dishwasher, gas cooktop and electric oven and heaps of bench space, Four double bedrooms, two in a wing of their own, are served by a stylishly renovated central bathroom and second sky-lit bathroom to the rear.</description>
</property>
</rentalProperties>
解释: 覆盖身份规则 http://www.dpawson.co.uk/xsl/sect2/identity.html使用与任何不需要的属性匹配的空模板。