X hits on this document

435 views

0 shares

1 downloads

0 comments

53 / 142

Transforming XML with XSLT

<h1>Pets</h1> <ul>

<!-- use the count function to determin <li>Total number of pets: <xsl:value-of

<!-- calculate the average age of the p and count functions, as well as th <li>Average age of pets: <xsl:value-of </ul> <p>Pets sorted by: <xsl:value-of select= <table> <thead> <tr> <td style="text-align: right; font-we <td style="text-align: right; font-we <td style="font-weight: bold">Type</t <td style="font-weight: bold">Color</ </tr> </thead> <xsl:apply-templates select="pet">

<!-- sort the pets by a particular sub <xsl:sort select="*[name()=$sortby]"/> </xsl:apply-templates> </table> </body> </html> </xsl:template>

<!-- pet --> <xsl:template match="pet">

<tr><xsl:apply-templates/></tr> </xsl:template>

<!-- name --> <xsl:template match="name">

<td style="text-align: right"><xsl:value-o </xsl:template>

<!-- age --> <xsl:template match="age">

<td style="text-align: right"><xsl:value-o </xsl:template>

<!-- type or color --> <xsl:template match="type | color">

<td><xsl:value-of select="."/></td> </xsl:template>

</xsl:stylesheet>

Here some same output:

45

e the number of pets --> select="count(pet)"/></li>

ets by using the sum e div operator --> select="sum(pet/age) div count(pet)"/>

"$sortby"/></p>

ight: bold">Name</td> ight: bold">Age</td> d> td>

element ($sortby); tricky! -->

f select="."/></td>

f select="."/></td>

Document info
Document views435
Page views441
Page last viewedThu Dec 08 06:06:54 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments