我需要帮助,我试图一次显示一行(游览),但它只显示整个表格

时间:2015-12-07 17:50:41

标签: xml xslt

我试图一次显示一行,并用一个按钮显示下一行,并且使用一个函数一次显示每个游览,而不是只在一个表中显示所有游览。我希望有人可以帮助我这个

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0"/>

<!-- start of root template -->
<xsl:template match="/">
<html>
<head>

<title>Tours</title>

</head>

<body>



<center>
                         <table border="5">
                        <tr>
                            <th colspan="8">Tours</th>
                        </tr>
                        <tr>
                           <th>Description</th>     
                           <th>Tour Name</th>
                           <th>Tour Photo</th>
                           <th>Tour Guide</th>
                           <th>Email</th>
                           <th>Tour Start</th>
                           <th>Tour End</th>
                           <th>Itinerary</th>

                            </tr>



                        <xsl:for-each select="tours/tour">


                                <tr>

                                    <td><xsl:value-of select="description"/></td>
                                    <td><xsl:value-of select="tourName" /> </td>
                                    <td><xsl:value-of select="tourPhoto"  /><th><img src="{tourPhoto}"></img></th></td>                                    
                                    <td><xsl:value-of select="tourGuide" /></td>
                                    <td><xsl:value-of select="tdEmail" /></td>
                                    <td><xsl:value-of select="tourStart" /></td>
                                    <td><xsl:value-of select="tourEnd" /></td>
                                    <td><xsl:value-of select="itinerary"/></td>

                                </tr>


                       </xsl:for-each>

                    </table>


                </center>


            </body>
           </html>
        </xsl:template>
    <!-- end of root template -->

This is my xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="tour.xsl"?>


<tours>
<tour>
<description>
<p><i>Travel Scotland!</i> goes south to England and the Lake District.
     The tour leaves departs from London, taking an overnight train to Windemere,
     your gateway to the Lake District. Take some time to peruse the local
     shops or hike the mountains, following in the footsteps of William
     Wordsworth. With a week in the Lake District, you'll have plenty of time
     to discover all of its charms and wonders.</p>
     <p>From the Lake District, we go to York for two fun-filled days. Tour the
     awesome York Minster, one of the most beautiful cathedrals in Europe. York
     is also home to underground ruins of one of the earliest Roman settlements
     in Britain.</p>
     <p>The tour concludes with two days of sight-seeing and fun in London.     </p>
</description>
<tourName>The Lake District</tourName>

<tourPhoto>lake.jpg</tourPhoto>


<tourGuide>Mary Taylor</tourGuide>
<tdEmail>mailto:mtaylor@tscotland.com</tdEmail>
<tourStart>6/15/2003</tourStart>
<tourEnd>6/19/2003</tourEnd>
<itinerary>
<day>
<lu><p> <dayNumber>1</dayNumber>
<plan><p>London arrival</p></plan></p></lu>
</day>
<day>
<lu><p><dayNumber>2</dayNumber>
<plan>Train to Windemere</plan></p></lu>
</day>
<day>
<dayNumber>3</dayNumber>
<plan>Second day in Windemere</plan>
</day>
<day>
<dayNumber>4</dayNumber>
<plan>Trip to Ambleside</plan>
</day>
<day>
<dayNumber>5</dayNumber>
<plan>Hiking tour to Grasmere</plan>
</day>
<day>
<dayNumber>6</dayNumber>
<plan>Boating trip on Lake Windemere</plan>
</day>
<day>
<dayNumber>7</dayNumber>
<plan>Free day</plan>
</day>
<day>
<dayNumber>8</dayNumber>
<plan>Trip to Keswick and Honister Pass</plan>
</day>
<day>
<dayNumber>9</dayNumber>
<plan>Return to Ambleside</plan>
</day>
<day>
<dayNumber>10</dayNumber>
<plan>Train to York</plan>
</day>
<day>
<dayNumber>11</dayNumber>
<plan>Second day in York</plan>
</day>
<day>
<dayNumber>12</dayNumber>
<plan>Train to London</plan>
</day>
<day>
<dayNumber>13</dayNumber>
<plan>Second day in London</plan>
</day>
<day>
<dayNumber>14</dayNumber>
<plan>London departure</plan>   
</day>
</itinerary>   
</tour>

<tour>
<description>
<p>Join <i>Travel Scotland!</i> for a two-week tour of the Hebrides. The trip
     takes you to four of the beautiful Hebridean islands, including Fingal's
     Cave, featured in Medelssohn's <i>The Hebrides</i> Overture.</p>
<p>The tour starts with a train tour of the Highlands from Glasgow to Fort
     William. After an overnight stay in Fort William, we leave by train and ferry
     to the Isle of Skye. While there, you'll have a chance to tour Dunvegan
     Castle and visit the Black Cullins in southern Skye. A boat trip to Mallaig
     follows and tour through Moidart where we'll visit the most western point in
     Great Britain.</p>
<p>No tour of the Hebrides can be complete with a visit to Iona and Fingal's
     Cave. Plenty of time will be available for touring the abbey at Iona and 
     touring the ruins. Pay your respects at the grave of St. Columba who, as
     the legends tell it, was a disciple of St. Patrick and brought Christianity
     to the Highlands.</p>
     <p>You'll spend the next three days in Oban and on the Isle of Jura. Be sure
     to take some time to sample its world-famous scotch! The
     trip concludes with two days in Glasgow.</p>
</description>
<tourName>The Hebrides</tourName>
<tourPhoto>Hebrides.jpg</tourPhoto>
<tourGuide>Alan Simpson</tourGuide>
<tdEmail>mailto:asimpson@tscotland.com</tdEmail>
<tourStart>7/02/2003</tourStart>
<tourEnd>7/16/2003</tourEnd>
<itinerary>
<day>
<dayNumber>1</dayNumber>
<plan>Glasgow arrival</plan>
</day>
<day>
<dayNumber>2</dayNumber>
<plan>Train to Fort William</plan>
</day>
<day>
<dayNumber>3</dayNumber>
<plan>Train and boat ferry to the Isle of Skye</plan>
</day>
<day>
<dayNumber>4</dayNumber>
<plan>Tour of Skye</plan>
</day>
<day>
<dayNumber>5</dayNumber>
<plan>Boat trip to Mallaig, bus tour through Moidart</plan>
</day>
<day>
<dayNumber>6</dayNumber>
<plan>Boat trip to the Isle of Mull</plan>
</day>
<day>
<dayNumber>7</dayNumber>
<plan>Free day</plan>
</day>
<day>
<dayNumber>8</dayNumber>
<plan>Tour of Iona and Fingal's Cave</plan>
</day>
<day>
<dayNumber>9</dayNumber>
<plan>Boat trip to Oban</plan>
</day>
<day>
<dayNumber>10</dayNumber>
<plan>Bus and boat tour to Jura</plan>
</day>
<day>
<dayNumber>11</dayNumber>
<plan>Second day on Jura</plan>
</day>
<day>
<dayNumber>12</dayNumber>
<plan>Bus tour to Glasgow</plan>
</day>
<day>
<dayNumber>13</dayNumber>
<plan>Second day in Glasgow</plan>
</day>
<day>
<dayNumber>14</dayNumber>
<plan>Glasgow departure</plan>   
</day>
</itinerary>   
</tour>
</tours>

1 个答案:

答案 0 :(得分:0)

试试这个......

tour.xsl

<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
    xmlns:prop="http://saxonica.com/ns/html-property"
    xmlns:style="http://saxonica.com/ns/html-style-property"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs prop"
    extension-element-prefixes="ixsl"
    version="2.0">


<xsl:template match="/">       
  <xsl:variable name="count" select="count( tours/tour)" as="xs:integer" />    
  <xsl:result-document href="#tour-body" method="ixsl:replace-content">
    <xsl:apply-templates select="tours/tour[1]" />    
  </xsl:result-document>   
  <xsl:for-each select="ixsl:page()/html/body/input[@id = ('btnPrev','btnNext')]">
    <xsl:choose>  
      <xsl:when test="(@id eq 'btnNext') and ($count gt 1)">    
        <ixsl:remove-attribute name="disabled"/>  
      </xsl:when>  
      <xsl:otherwise>    
        <ixsl:set-attribute name="disabled" select="true()"/>  
      </xsl:otherwise>    
    </xsl:choose>    
  </xsl:for-each>      
</xsl:template>

<xsl:template match="tour">  
  <tr>
    <td><xsl:apply-templates select="description/node()" /></td>     
    <td><xsl:value-of select="tourName"/></td>
  </tr>      
</xsl:template>     

<xsl:template match="@*|node()">  
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />      
  </xsl:copy>
</xsl:template>     

<xsl:template name="render-row">  
  <xsl:param name="new-idx" />    
  <xsl:param name="count"   />    
  <xsl:result-document href="#tour-index" method="ixsl:replace-content">
    <xsl:value-of select="$new-idx" />    
  </xsl:result-document>        
  <xsl:result-document href="#tour-body" method="ixsl:replace-content">
    <xsl:apply-templates select="ixsl:source()/tours/tour[$new-idx]" />    
  </xsl:result-document>   
  <xsl:for-each select="/html/body/input[@id = ('btnPrev','btnNext')]">
    <xsl:choose>  
      <xsl:when test="((@id eq 'btnPrev') and ($new-idx gt 1     )) or
                      ((@id eq 'btnNext') and ($new-idx lt $count))">    
        <ixsl:remove-attribute name="disabled"/>  
      </xsl:when>  
      <xsl:otherwise>    
        <ixsl:set-attribute name="disabled" select="true()"/>  
      </xsl:otherwise>    
    </xsl:choose>    
  </xsl:for-each>      
</xsl:template>     

<xsl:template match="input[@id eq 'btnPrev']" mode="ixsl:onclick">
  <xsl:variable name="idx"   select="/html/body/div[@id eq 'tour-index']" as="xs:integer" />    
  <xsl:variable name="count" select="count( ixsl:source()/tours/tour)" as="xs:integer" />    
  <xsl:if test="$idx ge 2">
    <xsl:call-template name="render-row">
      <xsl:with-param name="new-idx" select="$idx - 1" />    
      <xsl:with-param name="count"   select="$count" />    
    </xsl:call-template>        
  </xsl:if>     
</xsl:template>     

<xsl:template match="input[@id eq 'btnNext']" mode="ixsl:onclick">
  <xsl:variable name="idx"   select="/html/body/div[@id eq 'tour-index']" as="xs:integer" />    
  <xsl:variable name="count" select="count( ixsl:source()/tours/tour)" as="xs:integer" />    
  <xsl:if test="$idx lt $count">
    <xsl:call-template name="render-row">
      <xsl:with-param name="new-idx" select="$idx + 1" />    
      <xsl:with-param name="count"   select="$count" />    
    </xsl:call-template>        
  </xsl:if>     
</xsl:template>     

</xsl:transform>

tour.htm

<html>
<head>
  <title>Tours</title>
  <link href="tour.css" rel=stylesheet type="text/css">  
  <script type="text/javascript" language="javascript" src="js/Saxonce/Saxonce.nocache.js"></script> 
  <script type="application/xslt+xml" language="xslt2.0" src="tour.xsl" data-source="tour.xml"></script>  
</head>

<body>
<div id="tour-index" style="display:none">1</div>
<table>
  <thead>
    <tr><th colspan="8">Tours</th></tr>
    <tr>
      <th>Description</th>     
      <th>Tour Name</th>
    </tr> 
  </thead>
  <tbody id="tour-body"></tbody>    
</table>
<input type="button" id="btnPrev" value="previous" />    
<input type="button" id="btnNext" value="next" />    
</body>
</html>  

这假设您已经下载了Saxon CE。