Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.145.74.54] |
|
Страницы: (2) 1 [2] все ( Перейти к последнему сообщению ) |
Сообщ.
#16
,
|
|
|
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="intermediate/type"/> </xsl:template> <xsl:template match="type"> <xsl:apply-templates select="field[1]" mode="recursive-combine"> <xsl:with-param name="wire-name" select="@wireName"/> </xsl:apply-templates> </xsl:template> <xsl:template match="field[@isSimple='yes']" mode="recursive-combine"> <xsl:param name="accumulated" select="node()"/> <xsl:param name="wire-name"/> <xsl:param name="hidden" select="false()"/> <!-- в первый раз никто не скрыт, то есть опциональный field будет выведен --> <xsl:variable name="is-last" select="not(following-sibling::field)"/> <xsl:variable name="is-simple" select="@isSimple='yes'"/> <xsl:variable name="new-accumulated" select="$accumulated | current()[not($hidden) and $is-simple]"/> <xsl:if test="not($is-last)"> <xsl:apply-templates select="following-sibling::field[1]" mode="recursive-combine"> <xsl:with-param name="accumulated" select="$new-accumulated"/> <xsl:with-param name="wire-name" select="$wire-name"/> </xsl:apply-templates> </xsl:if> <xsl:apply-templates select="current()[$is-last]" mode="output"> <xsl:with-param name="accumulated" select="$new-accumulated"/> <xsl:with-param name="wire-name" select="$wire-name"/> </xsl:apply-templates> <xsl:apply-templates select="current()[@isOptional='yes'][not($hidden)][$is-simple]" mode="recursive-combine"> <xsl:with-param name="hidden" select="true()"/> <xsl:with-param name="accumulated" select="$accumulated"/> <xsl:with-param name="wire-name" select="$wire-name"/> </xsl:apply-templates> </xsl:template> <xsl:template match="*" mode="recursive-combine"/> <xsl:template match="field" mode="output"> <xsl:param name="accumulated"/> <xsl:param name="wire-name"/> <xsl:value-of select="concat('- ', $wire-name, ': [')"/> <xsl:for-each select="$accumulated"> <xsl:value-of select="concat( substring(', ', 1 div (not(position()=1)) ), @name )" /> </xsl:for-each> <xsl:value-of select="concat(']', '
')" /> </xsl:template> </xsl:stylesheet> 1. нафиг чойз в выводе, если до вывода доходят только простые поля? 2. переделал на ноде-сеты (смотри внимательно на парметр accumulated), потому нужно допилить под твой парсер - каждый по-своему с сетами работает. |
Сообщ.
#17
,
|
|
|
В строке 15:
<xsl:template match="field[@isSimple='yes']" mode="recursive-combine"> убрал [@isSimple='yes'], чтобы были выведены пустые элементы. Т.е. для <type wireName="box" name="Box" > <field name="rightCornerPoint" type="Point" isOptional="no" wireName="point" isSimple="no"/> <field name="leftCornerPoint" type="Point" isOptional="no" wireName="point" isSimple="no"/> </type> - box: [] Все остальное, вроде, правильно. Еще раз большое спасибо!!! |