Skip to content

Commit 497743a

Browse files
author
Bandarenka Yury
committed
up xslt
1 parent 22fa22b commit 497743a

File tree

3 files changed

+342
-32
lines changed

3 files changed

+342
-32
lines changed

Diff for: docs/xslt/xsl-apply-imports.md

+176
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,182 @@ Some binary operations
170170
1*2 = 21 (from str.xsl)
171171
```
172172

173+
### Пример 4
174+
175+
```xml tab=
176+
<?xml version="1.0"?>
177+
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
178+
<catalog>
179+
<book id="bk101">
180+
<title>XML Developer's Guide</title>
181+
<author>Gambardella, Matthew</author>
182+
<genre>Computer</genre>
183+
<price>44.95</price>
184+
<publish_date>2000-10-01</publish_date>
185+
<description>An in-depth look at creating applications with XML.</description>
186+
</book>
187+
<book id="bk102">
188+
<title>Midnight Rain</title>
189+
<author>Ralls, Kim</author>
190+
<genre>Fantasy</genre>
191+
<price>5.95</price>
192+
<publish_date>2000-12-16</publish_date>
193+
<description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
194+
</book>
195+
<book id="bk103">
196+
<title>Maeve Ascendant</title>
197+
<author>Corets, Eva</author>
198+
<genre>Fantasy</genre>
199+
<price>5.95</price>
200+
<publish_date>2000-11-17</publish_date>
201+
<description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description>
202+
</book>
203+
<book id="bk104">
204+
<title>Oberon's Legacy</title>
205+
<author>Corets, Eva</author>
206+
<genre>Fantasy</genre>
207+
<price>5.95</price>
208+
<publish_date>2001-03-10</publish_date>
209+
<description>In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.</description>
210+
</book>
211+
<book id="bk105">
212+
<title>The Sundered Grail</title>
213+
<author>Corets, Eva</author>
214+
<genre>Fantasy</genre>
215+
<price>5.95</price>
216+
<publish_date>2001-09-10</publish_date>
217+
<description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description>
218+
</book>
219+
<book id="bk106">
220+
<title>Lover Birds</title>
221+
<author>Randall, Cynthia</author>
222+
<genre>Romance</genre>
223+
<price>4.95</price>
224+
<publish_date>2000-09-02</publish_date>
225+
<description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description>
226+
</book>
227+
<book id="bk107">
228+
<title>Splish Splash</title>
229+
<author>Thurman, Paula</author>
230+
<genre>Romance</genre>
231+
<price>4.95</price>
232+
<publish_date>2000-11-02</publish_date>
233+
<description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description>
234+
</book>
235+
<book id="bk108">
236+
<title>Creepy Crawlies</title>
237+
<author>Knorr, Stefan</author>
238+
<genre>Horror</genre>
239+
<price>4.95</price>
240+
<publish_date>2000-12-06</publish_date>
241+
<description>An anthology of horror stories about roaches, centipedes, scorpions and other insects.</description>
242+
</book>
243+
<book id="bk109">
244+
<title>Paradox Lost</title>
245+
<author>Kress, Peter</author>
246+
<genre>Science Fiction</genre>
247+
<price>6.95</price>
248+
<publish_date>2000-11-02</publish_date>
249+
<description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description>
250+
</book>
251+
<book id="bk110">
252+
<title>Microsoft .NET: The Programming Bible</title>
253+
<author>O'Brien, Tim</author>
254+
<genre>Computer</genre>
255+
<price>36.95</price>
256+
<publish_date>2000-12-09</publish_date>
257+
<description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description>
258+
</book>
259+
<book id="bk111">
260+
<title>MSXML3: A Comprehensive Guide</title>
261+
<author>O'Brien, Tim</author>
262+
<genre>Computer</genre>
263+
<price>36.95</price>
264+
<publish_date>2000-12-01</publish_date>
265+
<description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description>
266+
</book>
267+
<book id="bk112">
268+
<title>Visual Studio 7: A Comprehensive Guide</title>
269+
<author>Galos, Mike</author>
270+
<genre>Computer</genre>
271+
<price>49.95</price>
272+
<publish_date>2001-04-16</publish_date>
273+
<description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description>
274+
</book>
275+
</catalog>
276+
```
277+
278+
```xslt tab="sample.xsl"
279+
<?xml version="1.0"?>
280+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
281+
<xsl:import href="sample-import.xsl"/>
282+
<xsl:output method="html"/>
283+
284+
<xsl:template match="book">
285+
<font face="Arial">
286+
<xsl:apply-imports/>
287+
</font>
288+
</xsl:template>
289+
290+
</xsl:stylesheet>
291+
```
292+
293+
```xslt tab="sample-import.xsl"
294+
<?xml version="1.0"?>
295+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
296+
297+
<!-- Override built-in template. -->
298+
<xsl:template match="text()"/>
299+
300+
<xsl:template match="/">
301+
<html>
302+
<body>
303+
<xsl:apply-templates/>
304+
</body>
305+
</html>
306+
</xsl:template>
307+
308+
<xsl:template match="book">
309+
<i>
310+
<xsl:apply-templates select="title"/>
311+
</i>
312+
<xsl:text> By: </xsl:text>
313+
<xsl:apply-templates select="author"/>
314+
<br/>
315+
</xsl:template>
316+
317+
<xsl:template match="title">
318+
<b>
319+
<xsl:value-of select="."/>
320+
</b>
321+
</xsl:template>
322+
323+
<xsl:template match="author">
324+
<font color="blue">
325+
<xsl:value-of select="."/>
326+
</font>
327+
</xsl:template>
328+
329+
</xsl:stylesheet>
330+
```
331+
332+
```html tab="Output"
333+
<html>
334+
<body>
335+
<font face="Arial"
336+
><i><b>XML Developer's Guide</b></i> By: <font color="blue">Gambardella, Matthew</font><br
337+
/></font>
338+
<font face="Arial"
339+
><i><b>Midnight Rain</b></i> By: <font color="blue">Ralls, Kim</font><br
340+
/></font>
341+
...
342+
<font face="Arial"
343+
><i><b>Visual Studio 7: A Comprehensive Guide</b></i> By: <font color="blue">Galos, Mike</font><br
344+
/></font>
345+
</body>
346+
</html>
347+
```
348+
173349
## См. также
174350

175351
- [`xsl:import`](/xslt/xsl-import/) -- импорт преобразований

Diff for: docs/xslt/xsl-apply-templates.md

+129-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
## Синтаксис
88

9-
### XSLT 1.0, XSLT 2.0 и XSLT 3.0
10-
119
```xml
1210
<xsl:apply-templates
1311
select = "выражение"
@@ -18,8 +16,11 @@
1816

1917
Атрибуты:
2018

21-
- `select`_необязательный_ атрибут, выражение вычисляет набор узлов к которым применяются преобразования. Если атрибут не задан — преобразования применяются ко всем потомкам текущего узла, включая текстовые.
22-
- `mode`_необязательный_ атрибут, указывает имя режима преобразования.
19+
`select`
20+
: _необязательный_ атрибут, выражение вычисляет набор узлов к которым применяются преобразования. Если атрибут не задан — преобразования применяются ко всем потомкам текущего узла, включая текстовые.
21+
22+
`mode`
23+
: _необязательный_ атрибут, указывает имя режима преобразования.
2324

2425
## Описание и примеры
2526

@@ -166,6 +167,129 @@
166167

167168
Начиная с шаблона `match="/"`, наша таблица стилей генерирует выходной документ вызовами разных шаблонов с тремя режимами `mode`. Три режима форматируют одну и ту же информацию тремя разными способами. В итоге таблица стилей создает тот же документ HTML, что и предыдущая таблица стилей.
168169

170+
### Пример 6
171+
172+
```xml tab=
173+
<?xml version="1.0"?>
174+
<?xml-stylesheet type="text/xsl" href="applyt.xsl" ?>
175+
<customers>
176+
<customer>
177+
<name>John Smith</name>
178+
<address>123 Oak St.</address>
179+
<state>WA</state>
180+
<phone>(206) 123-4567</phone>
181+
</customer>
182+
<customer>
183+
<name>Zack Zwyker</name>
184+
<address>368 Elm St.</address>
185+
<state>WA</state>
186+
<phone>(206) 423-4537</phone>
187+
</customer>
188+
<customer>
189+
<name>Albert Aikens</name>
190+
<address>368 Elm St.</address>
191+
<state>WA</state>
192+
<phone>(206) 423-4537</phone>
193+
</customer>
194+
<customer>
195+
<name>Albert Gandy</name>
196+
<address>6984 4th St.</address>
197+
<state>WA</state>
198+
<phone>(206) 433-4547</phone>
199+
</customer>
200+
<customer>
201+
<name>Peter Furst</name>
202+
<address>456 Pine Av.</address>
203+
<state>CA</state>
204+
<phone>(209) 765-4321</phone>
205+
</customer>
206+
<customer>
207+
<name>Dan Russell</name>
208+
<address>9876 Main St.</address>
209+
<state>PA</state>
210+
<phone>(323) 321-7654</phone>
211+
</customer>
212+
</customers>
213+
```
214+
215+
```xslt tab=
216+
<?xml version="1.0"?>
217+
<xsl:stylesheet version="1.0"
218+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
219+
220+
<xsl:template match="/">
221+
<HTML>
222+
<BODY>
223+
<TABLE border="1" cellspacing="0" cellpadding="2">
224+
<xsl:apply-templates select="customers/customer">
225+
<xsl:sort select="state"/>
226+
<xsl:sort select="name"/>
227+
</xsl:apply-templates>
228+
</TABLE>
229+
</BODY>
230+
</HTML>
231+
</xsl:template>
232+
233+
<xsl:template match="customer">
234+
<TR>
235+
<xsl:apply-templates select="name" />
236+
<xsl:apply-templates select="address" />
237+
<xsl:apply-templates select="state" />
238+
<xsl:apply-templates select="phone" />
239+
<xsl:apply-templates select="phone" mode="accountNumber"/>
240+
</TR>
241+
</xsl:template>
242+
243+
<xsl:template match="name">
244+
<TD STYLE="font-size:14pt font-family:serif">
245+
<xsl:apply-templates />
246+
</TD>
247+
</xsl:template>
248+
249+
<xsl:template match="address">
250+
<TD> <xsl:apply-templates /> </TD>
251+
</xsl:template>
252+
253+
<xsl:template match="state">
254+
<TD> <xsl:apply-templates /> </TD>
255+
</xsl:template>
256+
257+
<xsl:template match="phone">
258+
<TD> <xsl:apply-templates /> </TD>
259+
</xsl:template>
260+
261+
<xsl:template match="phone" mode="accountNumber">
262+
<TD STYLE="font-style:italic">
263+
1-<xsl:value-of select="."/>-001
264+
</TD>
265+
</xsl:template>
266+
267+
</xsl:stylesheet>
268+
```
269+
270+
```html tab="Output"
271+
<html>
272+
<body>
273+
<table border="1" cellspacing="0" cellpadding="2">
274+
<tr>
275+
<td style="font-size:14pt; font-family:serif">Peter Furst</td>
276+
<td>456 Pine Av.</td>
277+
<td>CA</td>
278+
<td>(209) 765-4321</td>
279+
<td style="font-style:italic">
280+
1-(209) 765-4321-001
281+
</td>
282+
</tr>
283+
<tr>
284+
<td style="font-size:14pt; font-family:serif">Dan Russell</td>
285+
<td>9876 Main St.</td>
286+
...
287+
</tr>
288+
</table>
289+
</body>
290+
</html>
291+
```
292+
169293
## См. также
170294

171295
- [`xsl:call-template`](/xslt/xsl-call-template/) -- вызывает шаблон по имени.
@@ -176,4 +300,4 @@
176300
## Ссылки
177301

178302
- [`xsl:apply-templates`](https://developer.mozilla.org/en/XSLT/apply-templates) на MDN
179-
- [`xsl:apply-templates`](https://msdn.microsoft.com/en-us/library/ms256184.aspx) на MSDN
303+
- [`xsl:apply-templates`](<https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms256184(v=vs.100)>) на MSDN

0 commit comments

Comments
 (0)