I have this *.xml file
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xq340.xsl"?>
<wine grape="Cabernet">
<winery>Duckpond</winery>
<product>Merit Selection</product>
<year>1996</year>
<price>11.99</price>
</wine>
and this *.xsl file
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="winery">
<b><font size="10pt"><xsl:apply-templates/>
<xsl:text> </xsl:text>
<xsl:value-of select="../@grape"/></font></b><br/>
</xsl:template>
<xsl:template match="product">
<i><font size="10pt"><xsl:apply-templates/></font></i><br/>
</xsl:template>
<xsl:template match="year | price">
<font size="10pt"><xsl:apply-templates/></font><br/>
</xsl:template>
</xsl:stylesheet>
and somehow this is the output
Duckpond Cabernet
Merit Selection
1996
11.99
This is probably a lot, but I don't understand how the xsl steps through the xml to produce the html.
I would think it goes this way; the first template matches "winery", then it writes the bold and font tags. Here's where I get lost, the next instruction is "apply-templates" and this would activate the product template, write the italic tag and then "apply-templates" and write the font tags for year and price. In my "book" I should get something like this:
<b>
<font size="10pt">
<i>
<font size="10pt">
<font size="10pt">
<font size="10pt"></font>
<br/>
</font>
</font>
</i>
<br/>
</font>
</b>
<br/>
There also the "select="../@grape" which I assume is the one it's getting the actual xml nodes values; however, this is the name of and entire xml node, so I don't really know what it's getting.
Here're my questions:
- How does the first "apply-templates" returns "Duckpond"?
- When the first "apply-templates" in winery is called is it also trying to match itself again or does it try to match ALL OTHER templates or only templates showing after?
- When the first template end tag
</xsl:template>is hit, are the other two templates "product" and "year | price" called again?
Thanks. I guess I'm having problems trying to understand the flow of it all.