[XSL-LIST Mailing List Archive Home]
re: xsl stylesheet for shares table
Subject: re: xsl stylesheet for shares table|
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 04 Oct 2000 19:13:02 +0100
>I am new to xsl and I seem to be receiving an error associated with the text
>editor xml spy, it tells me that it is unable to reference a schema type.
I think you're problem's probably arising because you're trying to validate
the XSLT file. In order to validate the file, XML Spy needs to be able to
locate a reference to a DTD or a schema to tell it what
elements/attributes/entities and so on to expect. There's no reference to
one in your stylesheet file (no !DOCTYPE and no xsi:schemaLocation
attribute), so it can't find anything to validate the document against.
In fact, you never really need to validate XSLT stylesheets. They are very
difficult to validate because you can have any content in them you like:
the result tree might be of any kind, which means that most of the XSLT
elements could contain just about anything, and when you have an element
that could contain just about anything there's not much point validating in
the first place.
So don't try to validate it (don't click on that green tick) and stop it
from validating on load (Edit menu > Settings... item > File types tab,
select '.xsl' and check the 'Disable automatic validation' checkbox, I
think). Then XML Spy will stop complaining.
>I was also curious as to the set-up of my xsl, I am trying to create a
>simple table with share prices, gains and losses etc... is this a correct
It's hard to say without knowing what your XML source or your desired
output looks like. I'm going to have a guess from your brief description,
but I may be wildly wrong - I apologise in advance if what I say is useless
because of that.
I think your XML source probably looks something like:
With your template, the match="/" means that within the body of the
template, you're matching the root node, which is the node that sits at the
very top of the document structure. The document structure represented by
the above XML looks like:
+- (root node)
+- 'shares' element
+- 'share' element
| +- 'symbol' element
| +- 'date' element
| +- ...
+- 'share' element
+- 'symbol' element
+- 'date' element
When you say:
<xsl:apply-templates select="share" />
you're asking it to find it's child element named 'share'. Similarly, when
<xsl:value-of select="symbol" />
you're asking it to find it's child element named 'symbol'.
In the document structure shown above you can see that the root node only
has one child, the 'shares' element. What you probably want to do, within
your table, is create one row per 'share' element. You can do this by
applying templates to those elements, but you have to make sure that (a)
you're selecting them correctly and (b) you have a template that matches
them to create the rows. So, you should be applying templates within the
root-node-matching template using:
<xsl:apply-templates select="shares/share" />
You should also have template that creates a table row based on the share:
<td align="center"><value-of select="symbol"/></td>
<td align="center"><value-of select="date"/></td>
and should take out the bits that are generating table rows within the
I hope that this helps, but if you'd like any more detailed advice then
please give us an example of what your source looks like (and what you want
the result to look like).
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list