2016-05-16 5 views
1

私は現在、私の会社のSharePointページ用に以下のXML用のXSLTを作成しようとしていますが、何とかなっています。XSLT for-eachループはディバイダ要素よりも大きいですか?

私は日がテーブルに正しくなく、残りのデータを表示するために取得することができています here

のようなテーブルの形式でデータを提示したいです。私はこのxsltプログラミングのことについて、私が全面的なnoobであることを親切に指導してください。これは、初めてxsltコードを書こうとする試みです。

以下

がXMLである:

<?xml version="1.0"?> 
<channel> 
    <title>Singapore - Nowcast and Forecast </title> 
    <source>Meteorological Service Singapore</source> 
    <item> 
    <title>4 Day Forecast</title> 
    <forecastIssue time="04:41 AM" date="16-May-2016"/> 
    <weatherForecast> 
     <day>Tuesday</day> 
     <forecast>Warm. Afternoon thundery showers.</forecast> 
     <icon>TL</icon> 
     <temperature unit="Degrees Celsius" low="25" high="35"/> 
     <relativeHumidity unit="Percentage" low="55" high="95"/> 
     <wind speed="5 - 20" direction="SE"/> 
     <day>Wednesday</day> 
     <forecast>Late morning and early afternoon thundery showers.</forecast> 
     <icon>TL</icon> 
     <temperature unit="Degrees Celsius" low="25" high="34"/> 
     <relativeHumidity unit="Percentage" low="55" high="95"/> 
     <wind speed="10 - 20" direction="S"/> 
     <day>Thursday</day> 
     <forecast>Late morning and early afternoon thundery showers.</forecast> 
     <icon>TL</icon> 
     <temperature unit="Degrees Celsius" low="25" high="34"/> 
     <relativeHumidity unit="Percentage" low="55" high="95"/> 
     <wind speed="10 - 20" direction="S"/> 
     <day>Friday</day> 
     <forecast>Late morning and early afternoon thundery showers.</forecast> 
     <icon>TL</icon> 
     <temperature unit="Degrees Celsius" low="25" high="34"/> 
     <relativeHumidity unit="Percentage" low="55" high="95"/> 
     <wind speed="10 - 20" direction="SW"/> 
    </weatherForecast> 
    </item> 
</channel> 

これは私が書いたXSLTです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
<html> 
    <body> 
    <h2> 
     <xsl:value-of select="channel/item/title"/> 
    </h2> 
    <table border="1"> 
     <tr bgcolor="#FFCF00"> 
     <th>Day</th> 
     <th>Icon</th> 
     <th>Forecast</th> 
     <th>Low Temp.</th> 
     <th>High Temp.</th> 
     </tr> 
     <xsl:for-each select="channel/item/weatherForecast/day"> 
     <tr> 
      <td> 
      <xsl:value-of select="."/> 
      </td> 
      <td> 
      <xsl:value-of select="ancestor::weatherForecast/icon"/> 
      </td> 
      <td> 
      <xsl:value-of select="ancestor::weatherForecast/forecast"/> 
      </td> 
      <td> 
      <xsl:value-of select="ancestor::weatherForecast/temperature/@low"/> 
      <xsl:text>°C </xsl:text> 
      </td> 
      <td> 
      <xsl:value-of select="ancestor::weatherForecast/temperature/@high"/> 
      <xsl:text>°C </xsl:text> 
      </td> 
     </tr> 
     </xsl:for-each> 
    </table> 
    </body> 
</html> 

答えて

0

をあなたのXMLに基づいて、あなたは次の兄弟が欲しいday要素に割り当てます。

ので、代わりに

<xsl:value-of select="ancestor::weatherForecast/icon"/> 

使用

<xsl:value-of select="following-sibling::icon[1]"/> 

のあなたはforecasttemperature要素についても同様の変更を行うことができます。

+0

ありがとうございました。 – Xpose

関連する問題