parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

Хм… Попробовал – не хотит.

G_Z 26.07.2004 11:35 / 26.07.2004 11:37

У меня создаётся стойкое впечатление, что я верблюд.
По сему, приведу полностью тестовый xml и шаблон.
<?xml version="1.0" encoding="WINDOWS-1251"?>
<tree>
	<section id="1" parental_id="0" name="Главная" title="" url="/eng/" subin="1" active="0">
		<section id="2" parental_id="1" name="Продукты" title="" url="/eng/products/" subin="1" active="0">
			<section id="3" parental_id="2" name="Мониторы" title="" url="/eng/products/monitors/" subin="0" active="0"/>
			<section id="4" parental_id="2" name="Принтеры" title="" url="/eng/products/printers/" subin="0" active="0">
				<section id="5" parental_id="4" name="Лазерные" title="" url="/eng/products/printers/laser/" subin="0" active="0"/>
				<section id="6" parental_id="4" name="Струйные" title="" url="/eng/products/printers/toner/" subin="0" active="0"/>
			</section>
			<section id="7" parental_id="2" name="Винчестеры" title="" url="/eng/products/hdd/" subin="0" active="0">
				<section id="8" parental_id="7" name="IDE" title="" url="/eng/products/hdd/ide/" subin="0" active="0"/>
				<section id="9" parental_id="7" name="SCSI" title="" url="/eng/products/hdd/scsi/" subin="0" active="0"/>
				<section id="10" parental_id="7" name="Serial ATA" title="" url="/eng/products/hdd/sata/" subin="0" active="0"/>
			</section>
			<section id="11" parental_id="2" name="CD/DVD" title="" url="/eng/products/cd/" subin="1" active="0">
				<section id="12" parental_id="11" name="CD-RW" title="" url="/eng/products/cd/rw/" subin="0" active="0"/>
				<section id="13" parental_id="11" name="CD-ROM" title="" url="/eng/products/cd/rom/" subin="0" active="0"/>
				<section id="14" parental_id="11" name="DVD" title="" url="/eng/products/cd/dvd/" subin="1" active="0">
					<section id="15" parental_id="14" name="DVD-R" title="" url="/eng/products/cd/dvd/dvd-r/" subin="0" active="0"/>
					<section id="16" parental_id="14" name="DVD-RW" title="" url="/eng/products/cd/dvd/dvd-rw/" subin="1" active="1"/>
				</section>
			</section>
			<section id="17" parental_id="2" name="Мыши" title="" url="/eng/products/mice/" subin="0" active="0">
				<section id="18" parental_id="17" name="Шариковые" title="" url="/eng/products/mice/ball/" subin="0" active="0"/>
				<section id="19" parental_id="17" name="Оптические" title="" url="/eng/products/mice/optical/" subin="0" active="0"/>
				<section id="20" parental_id="17" name="Живые" title="" url="/eng/products/mice/live/" subin="0" active="0"/>
			</section>
			<section id="21" parental_id="2" name="Прочее" title="" url="/eng/products/else/" subin="0" active="0"/>
		</section>
		<section id="22" parental_id="1" name="Поддержка" title="" url="/eng/support/" subin="0" active="0"/>
		<section id="23" parental_id="1" name="Сотрудничество" title="" url="/eng/cooperation/" subin="0" active="0"/>
		<section id="24" parental_id="1" name="О сайте" title="" url="/eng/about/" subin="0" active="0"/>
		<section id="25" parental_id="1" name="Новости" title="" url="/eng/news/" subin="0" active="0">
			<section id="26" parental_id="25" name="Архив" title="" url="/eng/news/archive/" subin="0" active="0">
				<section id="27" parental_id="26" name="Новое в архиве" title="" url="/eng/news/archive/new/" subin="0" active="0"/>
			</section>
		</section>
	</section>
</tree>
+ шаблон, натравливаемый на него имеет общий вид («левые» куски заменены многоточиями):
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
	<xsl:key name="active" match="section" use="@active"/>

	<xsl:template match="/">

...

<xsl:call-template name="logo"/>

...
	</xsl:template>

<xsl:template name="logo">

...
			<xsl:for-each select="key('active', 1)">
				<a>
					<xsl:attribute name="href">
					<xsl:value-of select="@uri"/>
					</xsl:attribute>
					<img src="/img/logo_active.gif" width="78" height="35">
						<xsl:attribute name="border"><xsl:text>0</xsl:text></xsl:attribute>
					</img>
				</a>
				</xsl:for-each>
...
</xsl:template>
Вот в таком направлении.
Дело тут даже не в ключе, ибо можно выбрать узел как
<xsl:variable name="active_section" select="descendant-or-self::*[@active = 1]"/>
А потом также for-each’ить – получим то же.
Главное, если вывести
<xsl:copy-of select="descendant-or-self::*[@active = 1]" />
получим нормальную копию узла:
<section id="16" parental_id="14" name="DVD-RW" title="" url="/eng/products/cd/dvd/dvd-rw/" subin="1" active="1"/>
, а вот @uri получить – никак.