XML/XSLT stylesheet/list — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:26, 26 мая 2010
Содержание
Create index number
<source lang="xml">
File: Data.xml <?xml version="1.0"?> <list xml:lang="en">
<title>title 1</title> <listitem>item 1</listitem> <listitem>item 2</listitem> <listitem>item 3</listitem> <listitem xml:lang="sw">item 4</listitem> <listitem xml:lang="en-gb">item 5</listitem> <listitem xml:lang="zu">item 6</listitem> <listitem xml:lang="jz">item 7</listitem>
</list>
File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xhtml" encoding="ISO-8859-3" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/> <xsl:template match="/"> <html> <head> <title><xsl:value-of select="/list/title"/></title> </head> <body>
<xsl:value-of select="/list/title"/>
<xsl:for-each select="/list/listitem">
<xsl:number format="1. "/>
<xsl:value-of select="."/>
</xsl:for-each>
</body> </html> </xsl:template>
</xsl:stylesheet> Output: <?xml version="1.0" encoding="ISO-8859-3"?> <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head> <title>title 1</title> </head> <body>
title 1
1. item 1
</br>2. item 2
</br>3. item 3
</br>4. item 4
</br>5. item 5
</br>6. item 6
</br>7. item 7
</br>
</body>
</html>
</source>
Create list in transformation
<source lang="xml">
File: Data.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="Transform.xslt" ?> <neighbours>
<planet name="Venus"> <description> description </description> <diameter> 12104 km (7505 miles)</diameter> <moons> 0</moons> <meanTemp> 482C (900F)</meanTemp> <oneDay> 243.01 earth days</oneDay> <oneYear> 224.7 earth days</oneYear> </planet>
</neighbours> File: Transform.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="text()"/> <xsl:template match="neighbours"> <html> <head> <title>A simple HTML page</title> </head> <body>
Our neighbours
<xsl:apply-templates/>
2006. </body> </html> </xsl:template> <xsl:template match="planet"> <img width="100" height="100"> <xsl:attribute name="src"><xsl:value-of select="@name"/>.jpg </xsl:attribute> </img>
<xsl:value-of select="@name"/>
<xsl:value-of select="description/text()"/>
-
<xsl:apply-templates/>
</xsl:template> <xsl:template match="diameter">
</xsl:template> <xsl:template match="moons">
</xsl:template> <xsl:template match="meanTemp">
</xsl:template> <xsl:template match="oneDay">
</xsl:template> <xsl:template match="oneYear">
</xsl:template>
</xsl:stylesheet> Output: <html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>A simple HTML page</title></head> <body>
Our neighbours
<img width="100" height="100" src="Venus.jpg%0A ">Venus
description
- Diameter: 12104 km (7505 miles)
- Moons: 0
- Mean temperature: 482C (900F)
- Length of one day: 243.01 earth days
- Length of one year: 224.7 earth days
2006. </body>
</html>
</source>
Create ordered list
<source lang="xml">
File: Data.xml <?xml version="1.0"?> <manual type="assembly" id="model-rocket">
<parts-list> <part label="A" count="1">part 1</part> <part label="B" count="1">part 2</part> <part label="F" count="4">part 3</part> <part label="N" count="3">part 4</part> <part label="C" count="1">part 5</part> </parts-list> <instructions> <step> Glue <part ref="A" /> and <part ref="B" /> together. </step> <step> For each <part ref="F" /> , . </step> <step> Connect <part ref="C" /> </step> </instructions>
</manual> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> <xsl:output method="xml" encoding="ISO-8859-1" /> <xsl:template match="manual"> <html> <head> <title>Instructions Guide</title> </head> <body>
Instructions Guide
<xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="parts-list">
Parts
-
<xsl:apply-templates />
</xsl:template> <xsl:template match="part[@label]">
Steps
-
<xsl:apply-templates />
</xsl:template> <xsl:template match="step">
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="ISO-8859-1"?><html><head><title>Instructions Guide</title></head><body>Instructions Guide
Parts
- A
- part 1
- B
- part 2
- F
- part 3
- N
- part 4
- C
- part 5
Steps
- Glue part 1 (Part A) and part 2 (Part B) together.
- For each part 3 (Part F) , .
- Connect part 5 (Part C)
</body></html>
</source>