powered by simpleCommunicator - 2.0.50     © 2025 Programmizd 02
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / Xsl трансформация
3 сообщений из 3, страница 1 из 1
Xsl трансформация
    #38057290
vangok4322
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Помогите разобраться:
Имеется такой 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.
<bom titleTable="название" >
  <item itemId="090501029168" unitId="шт" itemPrice="67643">
    <month name="Январь">
      <itemName idx="0"  itemQty="4.0000" />
      <itemName idx="1" itemQty="4.0000" />
      <itemName idx="2" itemQty="2.0000" />
    </month>
    <month name="Февраль">
      <itemName idx="0" itemQty="3.0000" />
      <itemName idx="1" itemQty="6.0000" />
    </month>
    <month name="Март" />
    <month name="Апрель" />
    <month name="Май" />
    <month name="Июнь" />
    <month name="Июль" />
    <month name="Август" />
    <month name="Сентябрь" />
    <month name="Октябрь" />
    <month name="Ноябрь" />
    <month name="Декабрь" />
  </item>
  <item itemId="090501029173" unitId="шт" itemPrice="65464">
    <month name="Январь">
      <itemName idx="0" itemQty="2.0000" />
      <itemName idx="1" itemQty="10.0000" />
      <itemName idx="2" itemQty="40.0000" />
    </month>
    <month name="Февраль">
      <itemName idx="0" name="метла" itemQty="40.0000" />
      <itemName idx="1" name="метла" itemQty="12.0000" />
      <itemName idx="2" name="метла" itemQty="10.0000" />
      <itemName idx="3" name="метла" itemQty="2.0000" />
    </month>
    <month name="Март" />
    <month name="Апрель" />
    <month name="Май" />
    <month name="Июнь" />
    <month name="Июль" />
    <month name="Август" />
    <month name="Сентябрь" />
    <month name="Октябрь" />
    <month name="Ноябрь" />
    <month name="Декабрь" />
  </item>
</bom>



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.
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.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
<xsl:template mathc="bom">
   <xsl:for-each select="item">
			<xsl:sort order="ascending" select="@itemId"/>
			<Row>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"><xsl:value-of select="@itemId"/></Data></Cell>
				<Cell StyleID="s74"><Data Type="String"><xsl:value-of select="@unitId"/></Data></Cell>
				<Cell StyleID="s74"><Data Type="Number"><xsl:value-of select="@itemPrice"/></Data></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
				<Cell StyleID="s74"><Data Type="String"/></Cell>
			</Row>
			
		<xsl:apply-templates select="."/>
	</xsl:for-each>
</xsl:template>

<xsl:template match="item">
	<xsl:for-each select="month/itemName">
		<xsl:for-each select="preceding-sibling::itemName">
			<M>
				<xsl:value-of select="@idx"/>
			</M>
		</xsl:for-each>
		<xsl:choose>
			<xsl:when test="not(preceding::ItemName/@idx = ./@idx)">
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<xsl:apply-templates select="../../month">
					<xsl:with-param name="idx" select="@idx"/>
				</xsl:apply-templates>

				<Cell StyleID="s74" Index="19" ><Data Type="Number"/></Cell>
			</Row>
			</xsl:when>
		</xsl:choose>
	</xsl:for-each>		
	</xsl:template>
	
	<xsl:template match="month">
		<xsl:param name="idx"/>
		
		<Cell StyleID="s74">
		<xsl:choose>
			<xsl:when test="@name = 'Январь'">
				<xsl:attribute name="Index">7</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Февраль'">
				<xsl:attribute name="Index">8</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Март'">
				<xsl:attribute name="Index">9</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Апрель'">
				<xsl:attribute name="Index">10</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Май'">
				<xsl:attribute name="Index">11</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Июнь'">
				<xsl:attribute name="Index">12</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Июль'">
				<xsl:attribute name="Index">13</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Август'">
				<xsl:attribute name="Index">14</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Сентябрь'">
				<xsl:attribute name="Index">15</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Октябрь'">
				<xsl:attribute name="Index">16</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Ноябрь'">
				<xsl:attribute name="Index">17</xsl:attribute>
			</xsl:when>
			<xsl:when test="@name = 'Декабрь'">
				<xsl:attribute name="Index">18</xsl:attribute>
			</xsl:when>
		</xsl:choose>
		<xsl:if test="itemName[@idx = $idx]">
		<Data ss:Type="Number">
			<xsl:value-of select="itemName[@idx = $idx]/@itemQty"/>
		</Data>
		</xsl:if>
		</Cell>
		
	</xsl:template>
  </xsl:stylesheet>




Необходимо получить такую структуру:

Код: 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.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
<Row>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String">090501029168</Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String">шт</Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="Number"></Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
			</Row>
<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">3.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" >
					<Data Type="Number"/>
				</Cell>
			</Row>
			<M>0</M>
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">6.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" />
			</Row>
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">2.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8"/>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19">
					<Data Type="Number"/>
				</Cell>
			</Row>
...
Рейтинг: 0 / 0
Xsl трансформация
    #38057293
vangok4322
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Собственно говоря надо получить вот такую структуру Для определенного итема должно идти так:
январь
февраль
Март
Апрель
....
Это если элементов itemName один, а в случае если несколько, тогда так
январь
февраль
Март
Апрель
....
январь
февраль
Март
Апрель
....
Уже 3-й день бьюсь с этим.((
В шаблоне итем уже и ограничивал с помощью preceding, но не получается вывести. На данном этапе она работает таким образом:
выводит хмл, который надо получить + добавляет первые два Row элемента.
То есть:
Код: 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.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
                         <Row>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String">090501029168</Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String">шт</Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="Number"></Data>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
				<Cell StyleID="s74">
					<Data Type="String"/>
				</Cell>
			</Row>
                        <Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">3.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" >
					<Data Type="Number"/>
				</Cell>
			</Row>
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">6.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" />
			</Row>
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">2.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8"/>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19">
					<Data Type="Number"/>
				</Cell>
			</Row>
                       <!--НАЧИНАЮТСЯ НЕ НУЖНЫЕ ЭЛЕМЕНТЫ-->
                        <Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">3.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" >
					<Data Type="Number"/>
				</Cell>
			</Row>
			<Row>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74"/>
				<Cell StyleID="s74" Index="7">
					<Data Type="Number">4.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="8">
					<Data Type="Number">6.0000</Data>
				</Cell>
				<Cell StyleID="s74" Index="9"/>
				<Cell StyleID="s74" Index="10"/>
				<Cell StyleID="s74" Index="11"/>
				<Cell StyleID="s74" Index="12"/>
				<Cell StyleID="s74" Index="13"/>
				<Cell StyleID="s74" Index="14"/>
				<Cell StyleID="s74" Index="15"/>
				<Cell StyleID="s74" Index="16"/>
				<Cell StyleID="s74" Index="17"/>
				<Cell StyleID="s74" Index="18"/>
				<Cell StyleID="s74" Index="19" />
			</Row>
                  <!--КОНЕЦ НЕ НУЖНЫХ ЭЛЕМЕНТОВ-->


Как от них избавиться не понимаю((
...
Рейтинг: 0 / 0
Xsl трансформация
    #38057322
vangok4322
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Проблема решена.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / Xsl трансформация
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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