XML/XSLT stylesheet/context — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:26, 26 мая 2010
Relative context
File: Data.xml
<book>
<title>title 1</title>
<chapter>
<title>chapter 1</title>
<para>line 1</para>
<para>line 2</para>
</chapter>
<chapter>
<title>title 2</title>
<para>line 3</para>
<para>line 4</para>
</chapter>
</book>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="title">
Title:
<xsl:apply-templates />
</xsl:template>
<xsl:template match="chapter/title">
Chapter title:
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?>
Title:
title 1
Chapter title:
chapter 1
line 1
line 2
Chapter title:
title 2
line 3
line 4
Relative context from root element
File: Data.xml
<wine grape="Chardonnay">
<product>product 2</product>
<year>1997</year>
<price>10.99</price>
</wine>
File: Transform.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
<xsl:template match="wine/year">
<vintage>
<xsl:apply-templates />
</vintage>
</xsl:template>
</xsl:stylesheet>
Output:
product 2
<vintage>1997</vintage>
10.99