powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / XSLT трансформировать XML в HTML
2 сообщений из 2, страница 1 из 1
XSLT трансформировать XML в HTML
    #38695451
dwyli
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
создать из xml файл HTML таблицы
дан xml:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
<atom>
    <source id="RFAE" description="CMR compiled data from Mikhailov, V.N. et al., USSR nuclear weapons - tests and peaceful nuclear explosions, 1949 through 1990, RFNC- VNIEF, 1996.">
        <event>
            <country> USSR </country>
            <date> 12/14/1956 </date>
            <time> 00:00:00.0 </time>
            <lat> 50.0000 </lat>
            <long> 78.0000 </long>
            <depth> 0.00 </depth>
            <yield> 40.00 </yield>
            <type> NACS </type>
        </event>
    </source>

    <source id="AEC" description="CMR compiled data from United State Atomic Energy Commission (as reported in PDE or ISC bulletins)">
        <event>
            <country> US </country>
            <date> 07/26/1957 </date>
            <time> 08:00:00.0 </time>
            <lat> 37.0518 </lat>
            <long> -116.0334 </long>
            <depth> 0.15 </depth>
            <yield> 0.00 </yield>
            <ymax> 20.00 </ymax>
            <type> NUCU </type>
            <name> Pascal-A </name>        
        </event>
        <event>
            <country> US </country>
            <date> 08/27/1957 </date>
            <time> 22:35:00.0 </time>
            <lat> 37.0491 </lat>
            <long> -116.0340 </long>
            <depth> 0.15 </depth>
            <yield> 0.00 </yield>
            <ymax> 20.00 </ymax>
            <type> NUCU </type>
            <name> Pascal-B </name>          
        </event>



также html должен выглядеть как этот файл
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   </head>
   <body>
      <h1>RFAE
         <table border="1">
            <tr>
               <th>Land</th>
               <th>Datum</th>
               <th>Type</th>
               <th>Name</th>
            </tr>
            <tr>
               <td> USSR </td>
               <td> 12/14/1956 </td>
               <td> NACS </td>
               <td></td>
            </tr>
         </table>
      </h1>
      <h1>AEC
         <table border="1">
            <tr>
               <th>Land</th>
               <th>Datum</th>
               <th>Type</th>
               <th>Name</th>
            </tr>
            <tr>
               <td> US </td>
               <td> 02/27/1974 </td>
               <td> NUCU </td>
               <td> Latir </td>
            </tr>
</table>
      </h1>
   </body>
</html>



вот что у меня пока получилось, не понимаю как работать с этими шаблонами, и данные о событиях (event) должны в таблице быть только yield больше 10.
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
   
    <xsl:output method="html"/>

    <xsl:template match="/">
        <html>
            <head/>
                       
           <body>
                  
        <h1> <xsl:apply-templates select="//source"></xsl:apply-templates>
           
        <tabele border="1">
            <tr>
               <th>country</th>
                <th>date</th>
                <th>type</th>
                <th>name</th>
            </tr>
            <xsl:for-each select="atom/source/event">
                <tr>
                    <td> <xsl:value-of select="country"></xsl:value-of></td>
                    <td> <xsl:value-of select="date"></xsl:value-of></td>
                    <td> <xsl:value-of select="type"></xsl:value-of></td>
                    <td> <xsl:value-of select="name"></xsl:value-of></td>
                </tr>
                
            </xsl:for-each>
                  
         </tabele>
        </h1>
             <xsl:apply-templates select="event"/>    
           </body>
        </html>
    </xsl:template>   
    
    <xsl:template match="source">
    <xsl:value-of select="@id"></xsl:value-of>
    </xsl:template>
    
  
    
    <xsl:template match="event[yield &gt;10]">
        <xsl:apply-templates select="event"/>
    </xsl:template>
</xsl:stylesheet>
...
Рейтинг: 0 / 0
XSLT трансформировать XML в HTML
    #38696584
Intelligent2010
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
dwyli,

Попробуйте так:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

   <xsl:output method="html"
   encoding="utf-8" />

   <xsl:template match="/">
      <html>
         <head/>
            
         <body>
            <xsl:for-each select="//source">
               <xsl:if test="number(event//yield) &gt; 10">
                  <h1>
                     <xsl:value-of select="@id"/>
                  </h1>
                  <table border="1">
                     <tr>
                        <th>Land</th>
                        <th>Datum</th>
                        <th>Type</th>
                        <th>Name</th>
                     </tr>
                     <xsl:for-each select="event">
                        <xsl:if test="number(yield) &gt; 10">
                           <tr>
                              <td>
                                 <xsl:value-of select="country"/>
                              </td>
                              <td>
                                 <xsl:value-of select="date"/>
                              </td>
                              <td>
                                 <xsl:value-of select="type"/>
                              </td>
                              <td>
                                 <xsl:choose>
                                    <xsl:when test="string-length(name) = 0">&#xA0;</xsl:when>
                                    <xsl:otherwise>
                                       <xsl:value-of select="name"/>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </td>
                           </tr>
                        </xsl:if>
                     </xsl:for-each>
                  </table>
               </xsl:if>
            </xsl:for-each>            
         </body>
      </html>
   </xsl:template>   
</xsl:stylesheet>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / XSLT трансформировать XML в HTML
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]