954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

XML to XML using XSLT problem

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 , 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>
shanwise101
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Please post your input and expected output.

mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
 

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!

shanwise101
Newbie Poster
2 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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>
mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: