Jump to content
Sign in to follow this  
XMLTorrent

XSLT Question

Recommended Posts

If it's at all possible, is there a way to get a hold of attributes in your root element in XSL so that I can display them?I think I better include an example. Here is my XML code:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><?xml-stylesheet type="text/xsl" href="DictionaryDisp.xsl"?><!DOCTYPE book [	<!ELEMENT book (term+, type_of_speech+, definition+, root+)>  <!ATTLIST book  	title CDATA #REQUIRED  	isbn CDATA #REQUIRED  	publisher CDATA #REQUIRED  	type (paperback | hardback) #REQUIRED  >	<!ELEMENT term (#PCDATA)>	<!ELEMENT type_of_speech (#PCDATA)>	<!ELEMENT definition (#PCDATA)>	<!ELEMENT root (#PCDATA)>]><book title="The American Heritage School Dictionary" isbn="0-395-24739-4" publisher="Houghton Mifflin" type="hardback">	<term>a, A</term>	<type_of_speech>noun, plural</type_of_speech>	<definition>The first letter of the English alphabet; The best of highest of a grade, as in school; In music, the sixth tone in the scale of C-major.</definition>	<root>N/A</root></book>

The problem I'm having is that in my XSL document, I can't figure out how to get a hold of the attributes that the root element (book) contains. Does anyone know how to do this?ugh Those stupid code tags in the post truncated my indents. :)

Share this post


Link to post
Share on other sites

OK,I'm only a novice, but I'd lay out the structure differently.You have a book element, but the book element needs it's attributes changing to child elements.If you have a look at the W3Schools best practices, it says that the only attribute that should form part of the element tag is the id attribute.If you were to re-define your book so that it looked like this:<book> <title />

Share this post


Link to post
Share on other sites

OK,I'm only a novice, but I'd lay out the structure differently.You have a book element, but the book element needs it's attributes changing to child elements.If you have a look at the W3Schools tutorials on xml, they say that the only attribute that should form part of the element tag is the id attribute.If you were to re-define your book so that it looked like this:<book id="unique reference in here"> <title /> <publisher /> <type />..</book> That way you can use xsl to extract all the information you need about the book without having to worry about using attributes.Other members will probably have better suggestions, but this might help ease your burden.Hope this helps.Dooberry :)

Share this post


Link to post
Share on other sites

I had thought about that too but I had my doubts about doing that because I was reading an XML book and it said that attributes were usually meant for data that was less relevant to your actual document. The title, publisher, type, etc.. are less relevant to my document than the actual contents of the book but are relevant enough to be mentioned in the document. I think I might just place the attributes in the root element itself because I can't figure out how to get a hold of them. Thanks for the response.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...