Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2004, 04:22 AM
Registered User
 
Join Date: Mar 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in displaying the value of an attribute

Hi All,

I am new to XSLT.
I have the following XML file:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="address.xsl"?>
<!DOCTYPE address-book SYSTEM "address.dtd">
<address-book>
    <entry>
        <name>ABC</name>
        <email href = "abc@yahoo.com" />
    </entry>
    <entry>
        <name>XYZ</name>
        <email href = "xyz@yahoo.com" />
    </entry>
</address-book>


My XSL file for the same is:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
<xsl:template match = "/" >
    <html>
        <body>
            <table border = "1" cellspacing = "0" cellpadding = "0">
                <xsl:apply-templates />
            </table>
        </body>
    </html>
</xsl:template>
<xsl:template match = "*" >
    <xsl:apply-templates />
</xsl:template>
<xsl:template match = "address-book/entry" >
    <xsl:apply-templates />
</xsl:template>
<xsl:template match = "name">
    <tr>
    <td>Name</td>
    <td>
        <b><xsl:value-of select = "." /></b>
    </td>
    </tr>
</xsl:template>
<xsl:template match = "email">
    <tr>
    <td>Email</td>
    <td>
        <xsl:value-of select = "." />
    </td>
    </tr>
</xsl:template>
</xsl:stylesheet>



I want Name and Email to be displayed in the table. Name is getting displayed but since Email is specified as an attribute, I am unable to display it. Is there any way by which I can display the value of an attribute?




 
Old March 10th, 2004, 05:54 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Change
Code:
<xsl:template match = "email">
    <tr>
    <td>Email</td>
    <td>
        <xsl:value-of select = "." />
    </td>
    </tr>
</xsl:template>
to
[code]
<xsl:template match = "email">
    <tr>
    <td>Email</td>
    <td>
        <xsl:value-of select = "@href" />
    </td>
    </tr>
</xsl:template>
[code]

Joe (MVP - xml)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in XSLT with "//" in attribute value kaps77 XSLT 3 November 6th, 2007 10:57 AM
input attribute problem skyangel17 XSLT 4 August 1st, 2007 01:44 AM
Attribute.add and Refresh Problem Ardvisoor ASP.NET 2.0 Professional 3 July 25th, 2006 12:10 PM
attribute problem muki XSLT 1 November 13th, 2005 12:26 PM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.