X hits on this document

521 views

0 shares

1 downloads

0 comments

54 / 142

Transforming XML with XSLT

Using XSLT to create other types of text files

This final example uses the pets.xml file, again. This time the XSLT file is used to create another type of output, namely a very simple set of SQL statements. The point of this example is to illustrate how the pets.xml file can be repurposed. Once for display, and once for storage. Use this command to see the result: xsltproc -o pets.sql pets2sql.xsl pets.xml . What could you do to make the output prettier?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- pets2sql.xsl -->

<!-- create plain o' text output --> <xsl:output method="text" />

<!-- find each each pet --> <xsl:template match="pets">

<!-- loop through each pet --> <xsl:for-each select="pet">

<!-- output an SQL INSERT statement for the pet --> INSERT INTO pets (name, age, type, color) WITH VALUES ('<xsl:value-of select="name" />', '<xsl:value-of select="age" />', '<xsl:value-of select="type" />', '<xsl:value-of select="color" />');

46

Document info
Document views521
Page views527
Page last viewedWed Jan 18 09:16:20 UTC 2017
Pages142
Paragraphs3126
Words34660

Comments