<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897789</guid>
        <pubDate>Fri, 20 May 2011 10:08:37 +0000</pubDate>
        <title>Как найти все узлы между двумя узлами с помощью XSLT?</title>
        <link>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897789</link>
        <description><![CDATA[Hinikato: Запустив я вижу что работает&#33; <strong class='tag-b'>ss</strong>, Спасибо огромное, Вы Мастер&#33;&#33;&#33;]]></description>
        <author>Hinikato</author>
        <category>XML, XSL, XSLT</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897577</guid>
        <pubDate>Fri, 20 May 2011 06:21:59 +0000</pubDate>
        <title>Как найти все узлы между двумя узлами с помощью XSLT?</title>
        <link>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897577</link>
        <description><![CDATA[ss: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&#62;</div><div class="code_line">&#60;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;/&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;pricelist&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;pricelist/category&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/pricelist&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;category&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;pricelist/category&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;category name=&quot;{./text()}&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;current()[following-sibling::*[1][self::product]]&quot; mode=&quot;unknown&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;.&quot; mode=&quot;vendors&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/category&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;*&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&#60;!--//////////////////////////////////////////////////////////////////////////////--&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;category&quot; mode=&quot;unknown&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;vendor name=&quot;Unknown&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;following-sibling::*[1][self::product]&quot; mode=&quot;products&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;*&quot; mode=&quot;unknown&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&#60;!--//////////////////////////////////////////////////////////////////////////////--&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;product&quot; mode=&quot;products&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:copy-of select=&quot;.&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;following-sibling::*[1][self::product]&quot; mode=&quot;products&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;*&quot; mode=&quot;products&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&#60;!--//////////////////////////////////////////////////////////////////////////////--&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;vendor&quot; mode=&quot;vendor&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;vendor name=&quot;{./text()}&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;following-sibling::*[1][self::product]&quot; mode=&quot;products&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;*&quot; mode=&quot;vendor&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&#60;!--//////////////////////////////////////////////////////////////////////////////--&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;category | vendor&quot; mode=&quot;vendors&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;.&quot; mode=&quot;vendor&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:variable name=&quot;first_vendor&quot; select=&quot;following-sibling::vendor[1]&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:variable name=&quot;next_category&quot; select=&quot;following-sibling::category[1]&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;$first_vendor[not(. = $next_category/following-sibling::*)]&quot; mode=&quot;vendors&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;*&quot; mode=&quot;vendors&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&#60;/xsl:stylesheet&#62;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>]]></description>
        <author>ss</author>
        <category>XML, XSL, XSLT</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897493</guid>
        <pubDate>Thu, 19 May 2011 21:18:02 +0000</pubDate>
        <title>Как найти все узлы между двумя узлами с помощью XSLT?</title>
        <link>https://forum.sources.ru/index.php?showtopic=331969&amp;view=findpost&amp;p=2897493</link>
        <description><![CDATA[Hinikato: Здравствуйте&#33;<br>
<br>
Прошу помощи в решении следующей задачи: у меня есть XML документ, упрощенно для лучшего понимания задачи такой:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&#62;</div><div class="code_line">&#60;pricelist&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;category&#62;Категория 1&#60;/category&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;vendor&#62;Производитель 1.1.&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 1.1.1&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 1.1.2&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 1.1.3&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;category&#62;Категория 2&#60;/category&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 2.1&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;vendor&#62;Производитель 2.1&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 2.1.1&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;product&#62;Продукт 2.1.2&#60;/product&#62;</div><div class="code_line">&#60;/pricelist&#62;</div></ol></div></div></div></div><br>
Нужно его преобразовать в древовидный вид, а именно такой:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&#62;</div><div class="code_line">&#60;pricelist&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;category name=&quot;Категория 1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;vendor name=&quot;Производитель 1.1.&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 1.1.1&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 1.1.2&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 1.1.3&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;/category&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;category name=&quot;Категория 2&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;vendor name=&quot;Unknown&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 2.x&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;vendor name=&quot;Производитель 2.1&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 2.1.1&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;product&#62;Продукт 2.1.2&#60;/product&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/vendor&#62;</div><div class="code_line">&nbsp;&nbsp;&#60;/category&#62;</div><div class="code_line">&#60;/pricelist&#62;</div></ol></div></div></div></div><br>
Некоторые пояснения:<br>
- продукты для которых не указан производитель попадают в специальный производитель с именем Unknown, такой Unknown производитель может быть только один в каждой категории.<br>
- цифры у продуктов и производителей я добавил только для примера.<br>
- вообще в прайсе все имена категорий уникальны.<br>
- имена продуктов и производителей уникальны в пределах категории, но могут повторяться в пределах прайса.<br>
<br>
Я только начал изучать XLST, написал пока такой .xsl файл (могут быть ошибки, т.к. я его переделал для этого упрощенного примера:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;?xml version=&#39;1.0&#39; encoding=&quot;utf-8&quot;?&#62;</div><div class="code_line">&#60;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&#39;http://www.w3.org/1999/XSL/Transform&#39;&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;utf-8&quot; indent=&quot;yes&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:strip-space elements=&quot;*&quot;/&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;table&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;pricelist&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;xsl:apply-templates select=&quot;//category&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/pricelist&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;xsl:template match=&quot;category&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;xsl:variable name=&quot;category_name&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:value-of select=&quot;child::text()&quot;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/xsl:variable&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;category name=&quot;{$category_name}&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:variable name=&quot;next_category&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select=&quot;(self::node()/following-sibling::category)[1]&quot; /&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;xsl:variable name=&quot;current_category&quot; select=&quot;self::node()&quot;/&#62;</div><div class="code_line">&#60;!--</div><div class="code_line">Тут непонятно что писать...</div><div class="code_line">&nbsp;</div><div class="code_line">Я нашел фрагмент со следующей страницы: http://www.biglist.com/lists/xsl-list/archives/200201/msg00659.html</div><div class="code_line">&nbsp;&#60;xsl:copy-of select=&quot;following-sibling::*</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[generate-id(following-sibling::comma[1]) =</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; generate-id($next-comma)]&quot; /&#62;</div><div class="code_line">Но как его использовать здесь непонятно...</div><div class="code_line">--&#62; &nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;&#60;/category&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/xsl:template&#62;</div><div class="code_line">&#60;/xsl:stylesheet&#62;</div></ol></div></div></div></div><br>
Пояснения и вопрос еще я добавил в комментариях XML.<br>
<br>
Прошу помощи именно по XML части. Как можно получить на выходе документ в нужном виде из исходного?]]></description>
        <author>Hinikato</author>
        <category>XML, XSL, XSLT</category>
      </item>
	
      </channel>
      </rss>
	