Автор |
Сообщение |
Ex_Soft
Новичок

Зарегистрирован: 13.03.2009
Сообщения: 12
|
[13618]
Пт Мар 13, 2009 08:16
Не выполняется цикл
Дрозофила:
Код:
<?xml version="1.0" encoding="windows-1251"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<contract xmlns="http://localhost/contract" xmlns:othersperson="http://localhost/othersperson">
<contragent>Иванов Иван Иванович</contragent>
<date>2009.03.11</date>
<no>13</no>
<othersperson:othersperson>
<othersperson:contragent othersperson:date="1870.04.22">Ленин Владимир Ильич</othersperson:contragent>
<othersperson:contragent othersperson:date="1878.12.18">Сталин Иосиф Виссарионович</othersperson:contragent>
<othersperson:contragent othersperson:date="1894.04.17">Хрущев Никита Сергеевич</othersperson:contragent>
</othersperson:othersperson>
</contract>
Код:
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://localhost/contract" xmlns:othersperson="http://localhost/othersperson">
<xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" encoding="windows-1251" />
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="//my:contragent"/></title>
</head>
<body>
<p><strong><xsl:value-of select="//my:contragent"/></strong></p>
<p><xsl:value-of select="//my:date"/></p>
<p><xsl:value-of select="//my:no"/></p>
<table>
<caption>Others Person I</caption>
<thead>
<tr>
<th>Name</th>
<th>BirthDate</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="my:contract/othersperson:othersperson" />
</tbody>
</table>
<hr />
<table>
<caption>Others Person II</caption>
<thead>
<tr>
<th>Name</th>
<th>BirthDate</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="my:contract/othersperson:othersperson">
<tr>
<td><xsl:value-of select="othersperson:contragent" /></td>
<td><xsl:value-of select="othersperson:contragent/@othersperson:date" /></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="othersperson:othersperson">
<tr>
<td><xsl:value-of select="othersperson:contragent" /></td>
<td><xsl:value-of select="othersperson:contragent/@othersperson:date" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
В обоих случаях выводит только 1 TR (с Лениным). А почему?
_________________ "Helo, word!" - 17 errors 56 warnings
|
olpa
Любитель
Зарегистрирован: 23.04.2002
Сообщения: 981
Откуда: Санкт-Петербург
|
[13620]
Пт Мар 13, 2009 09:08
Цитата: В обоих случаях выводит только 1 TR (с Лениным). А почему?
Потому что XPath в xsl:value возвращает 3 узла, но xsl:value-of использует только первый. Надо примерно так:
Код:
<xsl:template match="othersperson:othersperson">
<xsl:apply-templates select="othersperson:contragent"/>
</xsl:template>
<xsl:template match="othersperson:contragent">
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:value-of select="@othersperson:date" /></td>
</tr>
</xsl:template>
|
Ex_Soft
Новичок

Зарегистрирован: 13.03.2009
Сообщения: 12
|
[13622]
Пт Мар 13, 2009 12:47
Общими усилиями - вот так все растолкалось
Код:
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://localhost/contract" xmlns:othersperson="http://localhost/othersperson">
<xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" encoding="windows-1251" />
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="//my:contragent"/></title>
</head>
<body>
<p><strong><xsl:value-of select="//my:contragent"/></strong></p>
<p><xsl:value-of select="//my:date"/></p>
<p><xsl:value-of select="//my:no"/></p>
<table>
<caption>Others Person I</caption>
<thead>
<tr>
<th>Name</th>
<th>BirthDate</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="my:contract/othersperson:othersperson" />
</tbody>
</table>
<hr />
<table>
<caption>Others Person II</caption>
<thead>
<tr>
<th>Name</th>
<th>BirthDate</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="my:contract/othersperson:othersperson/othersperson:contragent">
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:value-of select="@othersperson:date" /></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="othersperson:othersperson">
<xsl:apply-templates select="othersperson:contragent" />
</xsl:template>
<xsl:template match="othersperson:contragent">
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:value-of select="@othersperson:date" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
_________________ "Helo, word!" - 17 errors 56 warnings
|