2010-05-10 18 views
0

我有一個包含公司數據的XML文件,用於投資組合頁面上8個行業的30家公司。用戶可以選擇按行業對這些數據進行排序,並且這個XML文件將不斷添加。瀏覽已排序的XML數據(XSLT)

此排序在我的XSL文件中使用<xsl:choose>完成。例如:

<xsl:when test="(invest[@investid='con'])"> 
    <xsl:for-each select="$invest-port/portfolio/company[@industry='Communications']"> 
       <xsl:sort select="name" /> 
       <div class="invest-port-thumb"> 
        <a> 
         <xsl:attribute name="href"> 
         <xsl:value-of select="link" /> 
         </xsl:attribute> 
         </a> 
        </div> 
       </xsl:for-each> 
</xsl:when> 

當導航到一個單獨的公司的網頁,有在窗口底部的「以前」和「下一個」按鈕。我的問題是,我需要這些動態鏈接到已排序的XML數據中的前一個和下一個<link>元素。主XML文件的

部分:

<portfolio recact="1"> 

    <company industry="Industrial" status="Current" coid="1"> 
     <name>Horn Company</name> 
     <hq>Owensboro, KY</hq> 
     <link>horn.xml</link> 
    </company> 

    <company industry="Consumer" status="Current" coid="1"> 
     <name>Mike Waters Co</name> 
     <hq>Orlando, FL</hq> 
     <link>waters.xml</link> 
    </company> 

</portfolio> 

這可能嗎?還是有更簡單的方法來做到這一點? (比如將每個公司放在工業分割的XML文件中而不是一個)

任何洞察力將不勝感激!

+0

你沒有提供完整的信息,以便有人嘗試提供幫助。你的XML文檔在哪裏(最小,但完整!)。您的XSLT代碼在哪裏(最小但完整)?如果即使人們決定花時間在*「猜測模式」*,也不要指望快速或一致的答案。 – 2010-05-10 18:21:59

回答

0

使用preceding-siblingfollowing-sibling

編輯

<xsl:variable name="sorted"> 
     <xsl:for-each select="$invest-port/portfolio/company[@industry='Communications']"> 
      <xsl:sort select="name"/> 
      <xsl:copy-of select="."/> 
     </xsl:for-each> 
</xsl:variable> 

和之後,你可以做

<xsl:for-each select="$sorted/*"> 
    <xsl:apply-templates /> 
</xsl:for-each> 

所以,你可以使用前同輩及以下同輩

+0

申請後會工作嗎?還是將它視爲未被分類? – 2010-05-10 17:58:51

+0

@Andrew Parisi http://www.biglist.com/lists/xsl-list/archives/200504/msg01384.html – Gregoire 2010-05-10 18:07:45

+0

感謝您快速回復Gregoire。不幸的是,我對XSLT相當陌生,並且仍然有點困惑。我可能會問錯誤的問題。我問的是,這些方法是否可以處理來自XML文件的過濾數據?在我的示例代碼中顯示,我只顯示@ industry ='Communications'的節點(作爲其中一個行業的示例),所以我只想在匹配該特定屬性的節點之間來回導航。謝謝你的幫助! – 2010-05-10 18:19:23