开发者

Sort Data when not using a for-each loop

开发者 https://www.devze.com 2023-02-11 18:23 出处:网络
I want to sort my XML in a specific order based of the value of the node \"Reason\" I have my XML <AgentSales>

I want to sort my XML in a specific order based of the value of the node "Reason"

I have my XML

  <AgentSales>
    <AgentName>MEYER RICK</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>29:09</time>
  </AgentSales>
  <AgentSales>
    <AgentName>BALENTINE JAMES</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>16:07</time>
  </AgentSales>
  <AgentSales>
   开发者_如何学Python <AgentName>SHOEMAKER ERIC</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>08:21</time>
  </AgentSales>
  <AgentSales>
    <AgentName>HARVEY MICHAEL</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>02:11</time>
  </AgentSales>
  <AgentSales>
    <AgentName>MORRIS BRANDEN</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>02:05</time>
  </AgentSales>
  <AgentSales>
    <AgentName>FORER DAVID</AgentName>
    <State>Talking Out</State>
    <Reason>Undefined</Reason>
    <time>01:15</time>
  </AgentSales>

and here is my current style. All it does is ignores any AgentSales that has a State of "Talking Out" But then just goes down the line and shows the rest of the data as-is. I want to sort the data by Time while still not showing AgentSales with "Talking Out" and "Talking In" I am pretty sure I just have to update my select to:

<xsl:apply-templates select="NewDataSet/AgentSales[State!=\'Talking Out\'] || NewDataSet/AgentSales[State!=\'Talking In\']"/>

But how do I sort the rest of the data leftover?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
                <table cellpadding="3" cellspacing="0" width="390">
                    <tr>
                        <th style="text-align:left;"><span style="font:20px arial; font-weight:bold;">Agent Name</span></th>
                        <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">State</span></th>
                        <th style="text-align:center;"><span style="font:20px arial; font-weight:bold;">Time</span></th>
                    </tr>
                    <xsl:apply-templates select="NewDataSet/AgentSales[State!=\'Talking Out\']"/>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="AgentSales">
        <tr>
            <xsl:if test="(position() mod 2 = 1)">
                <xsl:attribute name="bgcolor">#cccccc</xsl:attribute>
            </xsl:if>
            <td style="text-align:left;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="AgentName"/></span></td>
            <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="State"/></span></td>
            <td style="text-align:center;"><span style="font:14px arial; font-weight:bold;"><xsl:value-of select="time"/></span></td>
        </tr>
    </xsl:template>

</xsl:stylesheet>


Use:

<xsl:apply-templates select=
  "NewDataSet/AgentSales
           [not(State='Talking Out')
          and
            not(State='Talking In')
           ]
"> 
  <xsl:sort select="time"/>
<xsl:apply-templates 


You can add a sort element to the apply templates, something like this.

<xsl:apply-templates select="NewDataSet/AgentSales[State!=\'Talking Out\']">
    <xsl:sort select="time" />
</xsl:apply-templates>

Here is a more detailed article that discusses this.

0

精彩评论

暂无评论...
验证码 换一张
取 消