2015-05-22 6 views
0

У меня есть этот xml. Как объединить узлы адреса с запятой и поместить его под заголовком таблицы адресов вместо индивидуального размещения каждого узла под заголовком таблицы. Я чувствую, что этот способ написания шаблона немного сложнее. Есть ли способ открыть его немного?Узлы конкатенации XML

<rentalProperties> 
<property available="yes" contact="0499584010"> 
<type>house</type> 
<price>430</price> 
<address> 
<streetNo>111</streetNo> 
<street>say, Burwood Road</street> 
<suburb>say, Hawthorn</suburb> 
<state>VIC</state> 
<zipcode>3122</zipcode> 
</address> 
<numberOfBedrooms>3</numberOfBedrooms> 
<numberOfBathrooms>1</numberOfBathrooms> 
<garage>1</garage> 
<description></description> 
</property> 
</rentalProperties> 

XSL Файл

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/rentalProperties"> 
<html> 
    <body> 
     <table border="1"> 
      <tr> 
       <th>Availability</th> 
       <th>Contact</th> 
       <th>Type</th> 
       <th>Price</th> 
       <th>Address</th> 
       <th>Bedrooms</th> 
       <th>Bathrooms</th> 
       <th>Garage</th> 
       <th>Description</th> 
      </tr> 
      <xsl:for-each select="property"> 
       <tr>  
        <xsl:apply-templates select="@* | *"/> 
       </tr> 
      </xsl:for-each> 
     </table> 
    </body> 
</html> 
</xsl:template> 
<xsl:template match="@available | @contact | type | price | string-join((address/streetNo/text(), address/street/text()),',') | numberOfBedrooms | numberOfBathrooms | garage | description"> 
<td>  
    <xsl:value-of select="." /> 
</td> 
</xsl:template> 
</xsl:stylesheet> 

ответ

0

Вы можете использовать функцию Concat так:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/rentalProperties"> 
<html> 
    <body> 
     <table border="1"> 
      <tr> 
       <th>Availability</th> 
       <th>Contact</th> 
       <th>Type</th> 
       <th>Price</th> 
       <th>Address</th> 
       <th>Bedrooms</th> 
       <th>Bathrooms</th> 
       <th>Garage</th> 
       <th>Description</th> 
      </tr> 
      <xsl:for-each select="property"> 
       <tr>  
        <xsl:apply-templates select="@* | *"/> 
       </tr> 
      </xsl:for-each> 
     </table> 
    </body> 
</html> 
</xsl:template> 
<xsl:template match="@available | @contact | type | price | numberOfBedrooms | numberOfBathrooms | garage | description"> 
<td>  
    <xsl:value-of select="." /> 
</td> 
</xsl:template> 
<xsl:template match="address"> 
<td> 
    <xsl:value-of select="concat(streetNo/text(), ',', street/text())"/> 
</td> 
</xsl:template> 

</xsl:stylesheet> 
Смежные вопросы