powered by simpleCommunicator - 2.0.50     © 2025 Programmizd 02
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / как?
10 сообщений из 10, страница 1 из 1
как?
    #38183192
ryde
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Уж простите меня новичка, но возникла ситуация.
есть входящий 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.
<?xml version="1.0" encoding="utf-8"?>
<rows>
<row 
DocumentNumberOmobus="Doc39U442014" 
TPCode="Котенев О" 
ClientCode="Авангард" 
ProductCode="10937" 
Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
 ></row>
<row 
DocumentNumberOmobus="Doc39U442014" 
TPCode="Котенев О" 
ClientCode="Авангард"
ProductCode="4807" 
Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
 ></row>
<row 
DocumentNumberOmobus="Doc40U442014" 
TPCode="Котенев О"
ClientCode="Эюбов К Э О"
ProductCode="10937"
Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
 ></row>
<row 
DocumentNumberOmobus="Doc40U442014" 
TPCode="Котенев О" 
ClientCode="Эюбов К Э О" 
ProductCode="4807" 
Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
 ></row>
</rows>



есть XSL:
Код: 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.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes"/>

<xsl:template match="/">
	<documents>
    <preorders>  
     <xsl:for-each select="//row">
     <preorder>
      <outercode>
	<xsl:value-of select="@DocumentNumberOmobus"/>
      </outercode>
      <date>
	<xsl:value-of select="@OrderDeliveryDate"/>
      </date>
      <employeecode>
	<xsl:value-of select="@TPCode"/>
      </employeecode>
      <buypointcode>
	<xsl:value-of select="@ClientCode"/>
      </buypointcode>
      <stockid>
	<xsl:value-of select="5"/>
	  </stockid>
      <comment>
	<xsl:value-of select="null"/>
      </comment>
      <body>
        <xsl:for-each select="//row">
	<item>
 	  <SKUcode>
	   <xsl:value-of select="@ProductCode"/>
	  </SKUcode>
          <quantity>
	   <xsl:value-of select="@Quantity"/>
	  </quantity>
	</item>
        </xsl:for-each>
      </body>
     </preorder>
     </xsl:for-each>
    </preorders>
    </documents>
 </xsl:template>
</xsl:stylesheet>



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.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
<?xml version="1.0" encoding="windows-1251"?>
<documents>
<preorders>
<preorder>
<outercode>Doc39U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Авангард</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
<preorder>
<outercode>Doc39U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Авангард</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
<preorder>
<outercode>Doc40U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Эюбов К Э О</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
<preorder>
<outercode>Doc40U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Эюбов К Э О</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
</preorders>
</documents>



а нужно:
Код: 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.
<?xml version="1.0" encoding="windows-1251"?>
<documents>
<preorders>
<preorder>
<outercode>Doc39U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Авангард</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
<preorder>
<outercode>Doc40U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Эюбов К Э О</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
<SKUcode>10937</SKUcode>
<quantity>100</quantity>
</item>
<item>
<SKUcode>4807</SKUcode>
<quantity>100</quantity>
</item>
</body>
</preorder>
</preorders>
</documents>



как мне сделать так, что бы <preorder> не дублировался, как во входящем файле?
спасибо!
...
Рейтинг: 0 / 0
как?
    #38183920
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rydeкак мне сделать так, что бы <preorder> не дублировался, как во входящем файле?Для начала определить условия по, которому, два узла считаются идентичными. Потому, что в исходном файле у Вас все узлы различные
...
Рейтинг: 0 / 0
как?
    #38183957
ryde
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
_Vasilisk_,
я это понимаю, просто не знаю как это реализовать, потому как совсем недавно начал изучать.
мне бы на примере)уж простите за наглость
...
Рейтинг: 0 / 0
как?
    #38183964
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rydeя это понимаюНу так озвучьте их. Или мы должны сами угадать?
...
Рейтинг: 0 / 0
как?
    #38183994
ryde
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
_Vasilisk_,
пардонте.
логичней будет по
Код: xml
1.
 DocumentNumberOmobus
...
Рейтинг: 0 / 0
как?
    #38184885
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rydeлогичней будет по
Код: xml
1.
 DocumentNumberOmobus

Код: xml
1.
2.
3.
4.
5.
6.
7.
<xsl:for-each select="//row">
  <xsl:if test="not(preceding-sibling::row[@DocumentNumberOmobus = current()/@DocumentNumberOmobus])">
     <preorder>
       .............
     </preorder>
  </xsl:if>
</xsl:for-each>
...
Рейтинг: 0 / 0
как?
    #38184991
ryde
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
_Vasilisk_,

теперь не дублируется, спасибо!
НО не все, если на входе разных DocumentNumberOmobus будут разные ProductCode="" Quantity="" , т.е.
Код: 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.
<rows>
<row 
DocumentNumberOmobus="Doc39U442014" 
TPCode="Котенев О" 
ClientCode="Авангард" 
   ProductCode="10937" 
   Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
></row>
<row 
DocumentNumberOmobus="Doc39U442014" 
TPCode="Котенев О" 
ClientCode="Авангард"
   ProductCode="4807" 
   Quantity="100" 
OrderDeliveryDate="12.03.2013 0:00:00" 
></row>
<row 
DocumentNumberOmobus="Doc40U442014" 
TPCode="Котенев О"
ClientCode="Эюбов К Э О"
   ProductCode="55555"
   Quantity="111"
OrderDeliveryDate="12.03.2013 0:00:00" 
></row>
<row 
DocumentNumberOmobus="Doc40U442014" 
TPCode="Котенев О" 
ClientCode="Эюбов К Э О" 
   ProductCode="444" 
   Quantity="144"
OrderDeliveryDate="12.03.2013 0:00:00" 
></row>
</rows>



то на выходе уже будет:
Код: 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.
<documents>
<preorders>
<preorder>
<outercode>Doc39U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Авангард</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
   <SKUcode>10937</SKUcode>
   <quantity>100</quantity>
</item>
<item>
   <SKUcode>4807</SKUcode>
   <quantity>100</quantity>
</item>
</body>
</preorder>
<preorder>
<outercode>Doc40U442014</outercode>
<date>12.03.2013 0:00:00</date>
<employeecode>Котенев О</employeecode>
<buypointcode>Эюбов К Э О</buypointcode>
<stockid>5</stockid>
<comment></comment>
<body>
<item>
   <SKUcode>10937</SKUcode>
   <quantity>100</quantity>
</item>
<item>
   <SKUcode>4807</SKUcode>
   <quantity>100</quantity>
</item>
</body>
</preorder>
</preorders>
</documents>



<SKUcode></SKUcode> и <quantity></quantity> берутся от первого. почему так получилось?!
...
Рейтинг: 0 / 0
как?
    #38185632
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
ryde<SKUcode></SKUcode> и <quantity></quantity> берутся от первого. почему так получилось?!Именно так, как Вы хотели. Вы хотели отбросить идентичные узлы. Согласно Вашему определению узлы считаются идентичными, если у них совпадает атрибут DocumentNumberOmobus. Какие вопросы?
...
Рейтинг: 0 / 0
как?
    #38187553
ryde
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
_Vasilisk_,
как мне поступить, что бы на выходе было так, как мне нужно?(
...
Рейтинг: 0 / 0
как?
    #38188058
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rydeкак мне поступить, что бы на выходе было так, как мне нужно?( 14047801
...
Рейтинг: 0 / 0
10 сообщений из 10, страница 1 из 1
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / как?
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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