René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
XSL: Accessing attribute values | ||
The XML file:
<?xml version="1.0"?> <persons> <person><name>Alex </name><contact type='phone' >01 234 567</contact><contact type='fax' >88 543 123</contact></person> <person><name>Bert </name><contact type='mobile'>98 765 432</contact><contact type='telex' >5 51 51 </contact></person> <person><name>Charlie</name><contact type='email' >c@def.qq </contact><contact type='phone' >14 144 144</contact></person> <person><name>Dave </name><contact type='phone' >77 666 555</contact><contact type='mobile'>44 222 111</contact></person> <person><name>Emila </name><contact type='mobile'>e@fed.qq </contact><contact type='fax' >77 888 999</contact></person> </persons>
The XSL file:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="person"> <br> <b> <xsl:value-of select="name" /> </b> <xsl:value-of select="contact[1]/@type"/>: <xsl:value-of select="contact[1]" />, <xsl:value-of select="contact[2]/@type"/>: <xsl:value-of select="contact[2]" /> </br> </xsl:template> </xsl:stylesheet>
The output (whitespaces manually modified):
<?xml version="1.0" encoding="UTF-8"?> <br><b>Alex </b>phone: 01 234 567 , fax: 88 543 123 </br> <br><b>Bert </b>mobile: 98 765 432, telex: 5 51 51 </br> <br><b>Charlie</b>email: c@def.qq , phone: 14 144 144 </br> <br><b>Dave </b>phone: 77 666 555 , mobile: 44 222 111</br> <br><b>Emila </b>mobile: e@fed.qq , fax: 77 888 999 </br> |