Jump to content

XSLT Question


XMLTorrent

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. :)

Link to comment
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 />

Link to comment
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 :)

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...