2015-02-06 70 views
0

我知道標題可能很難理解。我將列出XML和XSLT,希望它會更清晰。XSLT沒有選擇某一組節點(只有第一個兄弟?)

<?xml version="1.0"?> 
 
<software_inventory> 
 
    <software xmlns:xsi="Software.xsd"> 
 
    <title>Adobe Photoshop</title> 
 
    <vendor>Adobe</vendor> 
 
    <category>Graphics</category> 
 
    <support_platforms> 
 
     <Platform>Windows 7</Platform> 
 
     <Platform>Windows 8</Platform> 
 
     <Platform>Windows 8.1</Platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 2GB Hard Drive" Software_Requiremnts="32/64 bit" Price="399">CS 5.5</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Winzip</title> 
 
    <vendor>Winzip International</vendor> 
 
    <category>Utility</category> 
 
    <support_platforms> 
 
     <platform>Windows Vista</platform> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="2GB Ram 250MB Hard Drive" Software_Requiremnts="32/64 bit" Price="29.99">19</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Office 365</title> 
 
    <vendor>Microsoft</vendor> 
 
    <category>Productivity</category> 
 
    <support_platforms> 
 
     <platform>Windows Vista</platform> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 2GB Hard Drive" Software_Requiremnts="32/64 bit" Price="99">Office 365</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Visual Studio</title> 
 
    <vendor>Microsoft</vendor> 
 
    <category>Development</category> 
 
    <support_platforms>  
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 2GB Hard Drive" Software_Requiremnts="32/64 bit" Price="1199">2013</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Google Chrome</title> 
 
    <vendor>Google</vendor> 
 
    <category>Productivity</category> 
 
    <support_platforms> 
 
     <platforms>Windows Vista</platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="1GB Ram 250MB Hard Drive" Software_Requiremnts="32/64 bit" Price="0">23</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Microsoft SQL Server 2012</title> 
 
    <vendor>Microsoft</vendor> 
 
    <category>DBMS</category> 
 
    <support_platforms>  
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
     <platform>Windows Server 2012</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 4GB Hard Drive" Software_Requiremnts="64 bit" Price="3990">2012</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Microsoft Paint</title> 
 
    <vendor>Microsoft</vendor> 
 
    <category>Graphics</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
     <platform>Linux</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="16GB Ram 1TB Hard Drive" Software_Requiremnts="32/64 bit" Price="1000000">22</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Notepad</title> 
 
    <vendor>Microsoft</vendor> 
 
    <category>Development</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="32GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="500000">3</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Oracle Database</title> 
 
    <vendor>Oracle</vendor> 
 
    <category>DBMS</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
     <platform>Windows Server 2012</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="8GB Ram 4GB Hard Drive" Software_Requiremnts="64 bit" Price="4000">Enterprise Edition</Version> 
 
     <Version Hardware_Requirements="8GB Ram 3GB Hard Drive" Software_Requiremnts="64 bit" Price="3000">Standard Edition</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Adobe Dreamweaver</title> 
 
    <vendor>Adobe</vendor> 
 
    <category>Development</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="2GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="299">CS5</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Adobe Fireworks</title> 
 
    <vendor>Adobe</vendor> 
 
    <category>Graphics</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="2GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="399">CS5</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Adobe Flash</title> 
 
    <vendor>Adobe</vendor> 
 
    <category>Development</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 1GB Hard Drive" Software_Requiremnts="32/64 bit" Price="499">CS5</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Adobe Illustrator</title> 
 
    <vendor>Adobe</vendor> 
 
    <category>Development</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="499">CS5</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Google Earth Pro</title> 
 
    <vendor>Google</vendor> 
 
    <category>Productivity</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="999">14</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Eclipse</title> 
 
    <vendor>The Eclipse Foundation</vendor> 
 
    <category>Development</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="4GB Ram 500MB Hard Drive" Software_Requiremnts="32/64 bit" Price="0">12</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
    <software> 
 
    <title>Candy Crush Saga</title> 
 
    <vendor>King.com ltd.</vendor> 
 
    <category>Productivity</category> 
 
    <support_platforms> 
 
     <platform>Windows 7</platform> 
 
     <platform>Windows 8</platform> 
 
     <platform>Windows 8.1</platform> 
 
    </support_platforms> 
 
    <Approved_Versions> 
 
     <Version Hardware_Requirements="32GB Ram 500GB Hard Drive" Software_Requiremnts="32/64 bit" Price="2000000">99</Version> 
 
    </Approved_Versions> 
 
    </software> 
 
</software_inventory>

<?xml version="1.0" encoding="utf-8"?> 
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> 
 
    <xsl:output method="html"/> 
 
    <xsl:template match="/" > 
 
     <html> 
 
     <head> 
 
      <title>Software</title> 
 
     </head> 
 
     <body> 
 
      <h1>Software Titles for each category, sorted by price</h1>   
 
      <table border="1"> 
 
      <tr> 
 
       <th>Software Title</th> 
 
       <th>Category</th> 
 
       <th>Price</th>    
 
      </tr> 
 
      <xsl:for-each select="software_inventory/software"> 
 
       <xsl:sort select="category"/> 
 
       <xsl:sort select="Approved_Versions/Version/@Price" data-type="number"/>    
 
       <tr> 
 
       <td> 
 
        <xsl:value-of select="title"/> 
 
       </td> 
 
       <td> 
 
        <xsl:value-of select="category"/> 
 
       </td> 
 
       <td>$ 
 
        <xsl:value-of select="Approved_Versions/Version/@Price"/> 
 
       </td>     
 
       </tr> 
 
      </xsl:for-each> 
 
      </table> 
 
      <h1>Software Titles for each operating system, sorted by category</h1> 
 
      <table border="1"> 
 
      <tr> 
 
       <th>Software Title</th> 
 
       <th>Operating System</th> 
 
       <th>Category</th> 
 
      </tr> 
 
      <xsl:for-each select="software_inventory/software">    
 
       <xsl:sort select="category"/> 
 
       <tr> 
 
       <td> 
 
        <xsl:value-of select="title"/> 
 
       </td>     
 
       <td> 
 
        <xsl:for-each select="support_platforms/platform">      
 
        <xsl:value-of select="."/>, 
 
        <xsl:text>&#xA;&#xD;</xsl:text>      
 
        </xsl:for-each> 
 
       </td>     
 
       <td>     
 
        <xsl:value-of select="category"/> 
 
       </td> 
 
       </tr> 
 
      </xsl:for-each> 
 
      </table>    
 
     </body> 
 
     </html> 
 
     
 
    </xsl:template> 
 
</xsl:stylesheet>

enter image description here

請看看照片。您將看到平臺永遠不會添加到Adobe Photoshop的操作系統單元中。恰巧,Adobe Photoshop位於software_inventory節點下的列表頂部。我不知道這是否是原因。我嘗試了一下代碼,它從來沒有選擇Adobe Photoshop的平臺。有沒有人知道爲什麼會發生這種情況?我能做些什麼來解決它?

謝謝, 大衛

回答

1

這是因爲Adobe公司的Photoshop元素是

<Platform></Platform> 

後,檢查platform。這是區分大小寫的,請使用

<platform>Windows 7</platform> 

改爲。

+0

哦,我的。你是對的!這解決了它。我使用Visual Studio自動生成基於XML文件的XSD。現在我需要重新創建XSD,因爲我修復了這些標籤。非常感謝Jean。當它允許我時,我會將你的回答標記爲答案。 – 2015-02-06 02:52:34

+0

@David.Warwick不客氣:)。 – 2015-02-06 03:18:51

相關問題