Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use ATTLIST?

Status
Not open for further replies.

chantey

Instructor
Jan 28, 2004
11
GB
Hi,

I have the following DTD and XML data. It uses ATTLIST to describe the attributes of 'name'. I want to display the attlist contents using an XSL file.

For example, using the XSL template, I need it to be displayed as:

Fred
25
15th Dec 1962
0123428374

Is this possible? A sample of the DTD and XML is shown below.

<!DOCTYPE address_book [
<!ELEMENT address_book ( name, tel_no, ) >
<!ELEMENT name ( #PCDATA } >
<!ELEMENT tel_no ( #PCDATA ) >
<!ATTLIST name
age (CDATA) #REQUIRED
birthday (CDATA) #REQUIRED >
]>

<address_book>
<name age="25" birthday="15th Dec 1962">Fred</name>
<tel_no>0123428374</tel_no>
</address_book>
 
Hi Chantey

Does this help?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
 <xsl:template match="/">
  <html>
   <head/>
    <body>
	<xsl:for-each select="address_book">
	 <xsl:for-each select="name">
	  <xsl:for-each select="@age">
	   <xsl:value-of select="."/>
	  </xsl:for-each>
	 </xsl:for-each>
	</xsl:for-each>
	<br/>
	<xsl:for-each select="address_book">
	 <xsl:for-each select="name">
	  <xsl:for-each select="@birthday">
	   <xsl:value-of select="."/>
	  </xsl:for-each>
	 </xsl:for-each>
	</xsl:for-each>
	<br/>
	<xsl:for-each select="address_book">
	 <xsl:for-each select="name">
	  <xsl:apply-templates/>
	 </xsl:for-each>
	</xsl:for-each>
	<br/>
	<xsl:for-each select="address_book">
	 <xsl:for-each select="tel_no">
	  <xsl:apply-templates/>
	 </xsl:for-each>
	</xsl:for-each>
    </body>
   </html>
 </xsl:template>
</xsl:stylesheet>

Mike
 
You might want to shorten the xslt Mike posted a bit:
Code:
<xsl:template match="address_book">
  <xsl:value-of select="name"/>
  <br/>
  <xsl:value-of select="name/@age"/>
  <br/>
  <xsl:value-of select="name/@birthday"/>
  <br/>
  <xsl:value-of select="tel_no"/>
  <br/>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top