[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Displaying one section of XML file at a time -- posting again


Subject: Re: [xsl] Displaying one section of XML file at a time -- posting again
From: "Jon Gorman" <jonathan.gorman@xxxxxxxxx>
Date: Mon, 27 Mar 2006 16:49:32 -0600

> Will appreciate if you could take a look at my
> XML/XSLT/JS code and let me know what is missing or
> where I am going wrong.

Like I've mentioned before, it's useful to be able to look at all
stages of the transformation.



> My XML file:
> <cd id="1">

> <cd id="2">

Word of warning.  In the XML world id attributes tend to be special
(depending on the tools for specifying, but assuming a classical
approach) and shouldn't start with numbers.  The id would typically be
something like c1, perhaps.  I don't think this will cause an error
necessarily at any point, but it might in some tools.


> <h2>
> <a href='javascript:void(0);' onClick="toggle('$id')">
                                                                   ^^^^

I think you're trying to do attribute value templates.  See
http://www.w3.org/TR/xslt#attribute-value-templates.  Remember XSLT
doesn't know anything about the output format.  So if you do this it
will literally put out toggle($id) (view the generated source).

> <div style="display:none" id="$id">
                                              ^^^^^
And here you assign all the elements the literal id value $id.  Hence
there's a conflict in ids, and browsers will behave unpredictably.
Most will probably just grab the first element with that id.

You really do need to make sure you have some way of viewing the
generated html page.  Either using view generated source via a plugin
or browser setting or generating using a stand-alone processor.  This
would have been much easier to notice had you done this.  Both
elements have the id $id, and both javascript calls toggle the
function $id.

You might want to look more into event listeners with Javascript for
how you're setting it up once you are more comfortable with the
language, but I won't get into any detail (highly OT).

Jon Gorman


Current Thread
Keywords