Skip to content

Commit

Permalink
XHTML generation
Browse files Browse the repository at this point in the history
  • Loading branch information
syniuhin committed Nov 8, 2016
1 parent 98defd0 commit 8eb082d
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lab1/gen_xhtml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lxml import etree

xslt_root = etree.parse('pattern.xsl')
transorm = etree.XSLT(xslt_root)
xml_root = etree.parse('products.xml')
result_tree = transorm(xml_root)
result = str(result_tree)
with open("products.xhtml", "w") as out:
out.write(result)
27 changes: 27 additions & 0 deletions lab1/pattern.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>Products</h2>
<table border="1">
<tr bgcolor="#666666">
<th style="text-align:left">Имя</th>
<th style="text-align:left">Цена</th>
<th style="text-align:left">Описание</th>
<th style="text-align:left">Картинка</th>
</tr>
<xsl:for-each select="data/product">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="description"/></td>
<td><img><xsl:attribute name="src"><xsl:value-of select="image"/></xsl:attribute></img></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Loading

0 comments on commit 8eb082d

Please sign in to comment.