XML连接节点

时间:2015-05-22 14:06:53

标签: xml xslt

我有这个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>

1 个答案:

答案 0 :(得分:0)

您可以使用这样的concat函数:

cat file.txt | awk '{print $1}' | grep -v '\.' | sort -u | awk 'NF'