2010-05-10 70 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