只有Xslt中列出的第一个项目

时间:2016-01-08 17:00:20

标签: xml xslt

当只运行我的xml中的第一项时显示该表。我怎样才能得到它以便列出App节点中的所有项目?

XML:

MakeModel findByModelStartingWithIgnoreCase(String model); //SQL => LIKE 'model%'
MakeModel findByModelEndingWithIgnoreCase(String model); //SQL => LIKE '%model'
MakeModel findByModelContainingIgnoreCase(String model); //SQL => LIKE '%model%'

XSLT:

<?xml version="1.0" encoding="utf-8" ?>
<!--Chris Martin-->
<Software>
<Company Name="Microsoft">
  <App>
    <AppItem Price="$79.99" Version="2016" MultiOs="true" QualityRating="3" PriceRating="2">Office Word</AppItem>
    <AppItem Price="$109.99" Version="2016" MultiOs="true" QualityRating="3" PriceRating="2">Office PowerPoint</AppItem>
    <AppItem Price="$458.93" Version="2015" MultiOs="false" QualityRating="3" PriceRating="2">Office Visual Studio</AppItem>
    <AppItem Price="$149.99" Version="4" MultiOs="false" QualityRating="3" PriceRating="2">Expression Web</AppItem>
    <AppItem Price="$109.99" Version="2016" MultiOs="true" QualityRating="3" PriceRating="2">Office Excel</AppItem>
  </App>
</Company>
<Company Name="Adobe">
  <App>
    <AppItem Price="$19.99/mo" Version="CC" MultiOs="true" QualityRating="3" PriceRating="2">Photoshop</AppItem>
    <AppItem Price="$19.99/mo" Version="CC" MultiOs="true" QualityRating="3" PriceRating="2">Dreamweaver</AppItem>
    <AppItem Price="$19.99/mo" Version="CC" MultiOs="true" QualityRating="3" PriceRating="2">Premiere Pro</AppItem>
    <AppItem Price="$19.99/mo" Version="CC" MultiOs="true" QualityRating="3" PriceRating="2">After Affects</AppItem>
    <AppItem Price="$19.99/mo" Version="CC" MultiOs="true" QualityRating="3" PriceRating="2">InDesign</AppItem>
  </App>
</Company>
<Company Name="Apple">
  <App>
    <AppItem Price="$299.99" Version="10.2.2" MultiOs="false" QualityRating="3" PriceRating="3">Final Cut Pro</AppItem>
    <AppItem Price="$199.99" Version="10.2" MultiOs="false" QualityRating="3" PriceRating="3">Logic Pro X</AppItem>
  </App>
</Company>
<Company Name="Mars">
  <App>
    <AppItem Price="Free" Version="4.5.1" MultiOs="true" QualityRating="3" PriceRating="5">Eclipse</AppItem>
  </App>
</Company>
<Company Name="JetBrains">
  <App>
    <AppItem Price="$199.99" Version="15.0.2" MultiOs="true" QualityRating="3" PriceRating="3">IntelliJ IDEA</AppItem>
  </App>
</Company>
<Company Name="Broderbund">
  <App>
    <AppItem Price="$99.99" Version="4.0" MultiOs="false" QualityRating="3" PriceRating="3">Print Shop Pro 4</AppItem>
  </App>
</Company>
</Software>

这是我得到的输出的屏幕截图

screen shot

1 个答案:

答案 0 :(得分:1)

<xsl:for-each select="Software/Company/App/AppItem">
    <tr>
        <td>
            <xsl:value-of select="../../@Name"/>
        </td>
        <td>
            <xsl:value-of select="."/>
        </td>
        <td>
            <xsl:value-of select="@Price"/>
        </td>
        <td>
            <xsl:value-of select="@Version"/>
        </td>
        <td>
            <xsl:value-of select="@MultiOs"/>
        </td>
    </tr>
</xsl:for-each>

要按价格排序,您必须先从价格中删除所有非数字字符:

 <xsl:sort select="translate(@Price, translate(@Price, '.0123456789', ''), '')" data-type="number" order="ascending"/>