显示xml中的数据

时间:2011-09-16 05:45:45

标签: xml xslt

我有一个Web应用程序,它从xml读取数据并将其显示在网页的表格中。我使用xslt来定义表并从xml中获取数据并以表格方式显示它们。

我的要求是,假设xml文件中没有可用数据,我想在表格中显示“没有发现数据”这样的消息,如下面的屏幕截图所示:

enter image description here

我在这里附上了我的xml和xslt文件。有人请给我一个任何代码形式的解决方案吗?

XSLT文件

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">

    <html>
      <head>
        <title>VPGate Media Mixer</title>

        <meta http-equiv="expires" content="0"/>
        <meta http-equiv="pragma" content="no-cache"/>
        <meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
        <meta http-equiv="refresh" content="15"></meta>
        <script src="/Common/common.js\" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="style001.css" />
        <link rel="stylesheet" type="text/css" href="Grid.Default.css" />


      </head>

      <body class="WorkArea">
        <div class="divSummaryHeader" id="SummaryHeader">
          <h1>Media Mixer - VPGate</h1>

          <xsl:for-each select="MMDiagnostics/Conference">
            <h1>
              Media Mixer - <xsl:value-of select="name"/>
            </h1>
          </xsl:for-each>
        </div>

        &#160;



        <div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:790px;overflow:auto">

          <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
            <tr>
              <input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>

            </tr>
            <tr>
              <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Summary</td>
            </tr>

            <tr>
              <td>
                <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0"  >
                  <tr>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
                  </tr>

                  <xsl:for-each select="MediaMixer/Conference">
                    <!--<xsl:sort select="Name"/>-->
                    <xsl:if test="(position() mod 2 = 0)">

                      <tr class="rgAltRow SummaryTableDataRow">
                        <td valign = "top">
                          <xsl:value-of select="Name"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="ConfId"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="CompositeAddress"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="CompositePort"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="CompositeSsrc"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="NoOfParticipants"/>
                        </td>
                      </tr>
                    </xsl:if>

                    <xsl:if test="(position() mod 2 = 1)">
                      <td>
                        <tr class="rgRow SummaryTableDataRow">
                          <td valign = "top">
                            <xsl:value-of select="Name"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ConfId"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositeAddress"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositePort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositeSsrc"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="NoOfParticipants"/>
                          </td>
                        </tr>
                      </td>
                    </xsl:if>

                  </xsl:for-each>

                </table>
              </td>
            </tr>
          </table>

          &#160;

          <table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1"  >
            <tr>
              <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Details</td>
            </tr>

            <tr>
              <td>

                <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
                  <tr>

                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 1</td>
                    <td class="rgHeader SummaryTableHdrRow" style="white-space: nowrap;font-weight:bold;" >ID 2</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
                    <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
                  </tr>




                  <xsl:for-each select="MediaMixer/Conference/Participant">

                    <xsl:if test="(position() mod 2 = 0)">
                      <tr class="rgAltRow SummaryTableDataRow">



                        <td valign = "top">
                          <xsl:value-of select="ID1"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="ID2"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="ParticipantAddress"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="ParticipantListeningPort"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="MMListeningPort"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="SSRCFromParticipant"/>
                        </td>
                        <td valign = "top">
                          <xsl:value-of select="SSRCFromMM"/>
                        </td>
                      </tr>
                    </xsl:if>

                    <xsl:if test="(position() mod 2 = 1)">
                      <td>
                        <tr class="rgRow SummaryTableDataRow">
                          <td valign = "top">
                            <xsl:value-of select="ID1"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ID2"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ParticipantAddress"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ParticipantListeningPort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="MMListeningPort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="SSRCFromParticipant"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="SSRCFromMM"/>
                          </td>

                        </tr>
                      </td>
                    </xsl:if>
                  </xsl:for-each>

                </table>
              </td>
            </tr>
          </table>


          &#160;


          <div style="display:none">
            <iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
          </div>


        </div>

      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

XML文件

<?xml-stylesheet type="text/xsl" href="MMDiagnostics.xslt"?>

<MediaMixer>

  <Conference>
    <Name>Test</Name>
    <ConfId>1002</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48000</CompositePort>
    <CompositeSsrc>243324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>80542151</ID1>
      <ID2>4</ID2>
      <ParticipantAddress>192.168.177.40</ParticipantAddress>
      <ParticipantListeningPort>22000</ParticipantListeningPort>
      <MMListeningPort>45000</MMListeningPort>
      <SSRCFromParticipant>216541</SSRCFromParticipant>
      <SSRCFromMM>56481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>80542151</ID1>
      <ID2>7</ID2>
      <ParticipantAddress>192.168.177.40</ParticipantAddress>
      <ParticipantListeningPort>22000</ParticipantListeningPort>
      <MMListeningPort>45000</MMListeningPort>
      <SSRCFromParticipant>216541</SSRCFromParticipant>
      <SSRCFromMM>56481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>7825482</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.22</ParticipantAddress>
      <ParticipantListeningPort>22002</ParticipantListeningPort>
      <MMListeningPort>45002</MMListeningPort>
      <SSRCFromParticipant>3256</SSRCFromParticipant>
      <SSRCFromMM>14822456</SSRCFromMM>
    </Participant>

  </Conference>

  <Conference>
    <Name>Test002</Name>
    <ConfId>1002</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48005</CompositePort>
    <CompositeSsrc>353324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

     <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>5625482</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.20</ParticipantAddress>
      <ParticipantListeningPort>22006</ParticipantListeningPort>
      <MMListeningPort>45006</MMListeningPort>
      <SSRCFromParticipant>8256</SSRCFromParticipant>
      <SSRCFromMM>41822456</SSRCFromMM>
    </Participant>

  </Conference>

</MediaMixer>

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">




<html>
  <head>
    <title>VPGate Media Mixer</title>

    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
    <meta http-equiv="refresh" content="15"></meta>
    <script src="/Common/common.js\" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="style001.css" />
    <link rel="stylesheet" type="text/css" href="Grid.Default.css" />


  </head>

  <body class="WorkArea">
    <div class="divSummaryHeader" id="SummaryHeader">
      <h1>Media Mixer - VPGate</h1>

      <xsl:for-each select="MMDiagnostics/Conference">
        <h1>
          Media Mixer - <xsl:value-of select="name"/>
        </h1>
      </xsl:for-each>
    </div>

    &#160;



    <div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:790px;overflow:auto">

      <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
        <tr>
          <input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>

        </tr>
        <tr>
          <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Summary</td>
        </tr>

        <tr>
          <td>
            <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0"  >
              <tr>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
              </tr>
              <xsl:choose>
                <xsl:when test="count(//Participant)>0">
              <xsl:for-each select="MediaMixer/Conference">
                <!--<xsl:sort select="Name"/>-->
                <xsl:if test="(position() mod 2 = 0)">

                  <tr class="rgAltRow SummaryTableDataRow">
                    <td valign = "top">
                      <xsl:value-of select="Name"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="ConfId"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="CompositeAddress"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="CompositePort"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="CompositeSsrc"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="NoOfParticipants"/>
                    </td>
                  </tr>
                </xsl:if>

                <xsl:if test="(position() mod 2 = 1)">
                  <td>
                    <tr class="rgRow SummaryTableDataRow">
                      <td valign = "top">
                        <xsl:value-of select="Name"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="ConfId"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="CompositeAddress"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="CompositePort"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="CompositeSsrc"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="NoOfParticipants"/>
                      </td>
                    </tr>
                  </td>
                </xsl:if>

              </xsl:for-each>

                </xsl:when>
                <xsl:otherwise>
                  <tr>
                    <td> No data has been discovered..</td>
                  </tr>

                </xsl:otherwise>
              </xsl:choose>

            </table>
          </td>
        </tr>



      </table>

      &#160;

      <table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1"  >
        <tr>
          <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Details</td>
        </tr>

        <tr>
          <td>

            <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
              <tr>

                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 1</td>
                <td class="rgHeader SummaryTableHdrRow" style="white-space: nowrap;font-weight:bold;" >ID 2</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
              </tr>




              <xsl:for-each select="MediaMixer/Conference/Participant">

                <xsl:if test="(position() mod 2 = 0)">
                  <tr class="rgAltRow SummaryTableDataRow">



                    <td valign = "top">
                      <xsl:value-of select="ID1"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="ID2"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="ParticipantAddress"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="ParticipantListeningPort"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="MMListeningPort"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="SSRCFromParticipant"/>
                    </td>
                    <td valign = "top">
                      <xsl:value-of select="SSRCFromMM"/>
                    </td>
                  </tr>
                </xsl:if>

                <xsl:if test="(position() mod 2 = 1)">
                  <td>
                    <tr class="rgRow SummaryTableDataRow">
                      <td valign = "top">
                        <xsl:value-of select="ID1"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="ID2"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="ParticipantAddress"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="ParticipantListeningPort"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="MMListeningPort"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="SSRCFromParticipant"/>
                      </td>
                      <td valign = "top">
                        <xsl:value-of select="SSRCFromMM"/>
                      </td>

                    </tr>
                  </td>
                </xsl:if>
              </xsl:for-each>

            </table>
          </td>
        </tr>
      </table>


      &#160;


      <div style="display:none">
        <iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
      </div>


    </div>

  </body>
</html>


  </xsl:template>
</xsl:stylesheet>