Hi all,

I've got my xml displaying correctly using php and the xsl template below, but I only want to display properties with a type of either apartment or unit, and have more than 2 bedrooms. I can't for the life of me work this out. I've tried using <xsl:choose>, <xsl:when test=""> etc etc, but I just can't get it. Can you use these elements when transforming xml to xml? Any help would be greatly appreciated.

Here is the currentl xsl sheet:

<xsl:template match="/">
   <xsl:element name="RentalProperties">
      <xsl:apply-templates select="rentalProperties/property"/>
   </xsl:element>
</xsl:template>


<xsl:template match="rentalProperties/property/type">
   <xsl:element name="type" >
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>
 
<xsl:template match="rentalProperties/property/price">
   <xsl:element name="price" >
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>

<xsl:template match="rentalProperties/property/address">
   <xsl:element name="address" >
      <xsl:value-of select="streetNo"/>,<xsl:value-of select="street"/>,<xsl:value-of select="suburb"/>,<xsl:value-of select="state"/>,<xsl:value-of select="zipcode"/>, Australia
   </xsl:element>
</xsl:template>
 
  <xsl:template match="rentalProperties/property/numberOfBedrooms">
   <xsl:element name="numberOfBedrooms" >
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>
 
 <xsl:template match="rentalProperties/property/description">
   <xsl:element name="description" >
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>

Please post your input and expected output.

The input and output are pretty much identical, however here is an example:
original 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.</description>
	</property> 
</rentalProperties>

A sample out the output would be:

<RentalProperties>
<property>
<type>house</type>
<price>800</price>
<address>116,Warrigal Road,Camberwell,VIC,3124, Australia</address>
<numberOfBedrooms>4</numberOfBedrooms>
<description>
Ideal for the familly is this charming Californian Bungalow.
</description>
</property>
</RentalProperties>

However using the xsl sheet i posted previously, i want the output to have eliminated those properties WITHOUT a type equaling 'apartment' or 'unit' - such as the property above. Hope this makes sense!

Try the below:

<xsl:template match="rentalProperties">
   <RentalProperties>
   <xsl:for-each select="property">
   
   <xsl:choose>
   <xsl:when test="type[. = 'unit' or 'apartment']">
   <property>
      <xsl:copy-of select="type"/>
	  <xsl:copy-of select="price"/>
	  <address>
	  <xsl:value-of select="address/streetNo"/>,<xsl:value-of select="address/street"/>,<xsl:value-of select="address/suburb"/>,<xsl:value-of select="address/state"/>,<xsl:value-of select="address/zipcode"/>, Australia
	  </address>
	  <xsl:copy-of select="numberOfBedrooms"/>
	  <xsl:copy-of select="description"/>
	</property>
   </xsl:when>
      <xsl:otherwise/>
   </xsl:choose>
   </xsl:for-each>
   </RentalProperties>
</xsl:template>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.