467,211 Members | 1,205 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,211 developers. It's quick & easy.

Extracting Data from Schema Tags

Hi All,

I've been working on mining data from a schema file (all attribute
data so far) and have come to the point where I need to get information
that is contained in tags. For instance, <tag>My Data Here</tag>.
I've tried using the <xsl:value-of select="tag"/> element, but it does
not appear to work in schema files. Is this correct? Is there another
way to get at this data?

-James

Jul 20 '05 #1
  • viewed: 1415
Share:
4 Replies


Porthos wrote:

I've been working on mining data from a schema file (all attribute
data so far) and have come to the point where I need to get information
that is contained in tags. For instance, <tag>My Data Here</tag>.
I've tried using the <xsl:value-of select="tag"/> element, but it does
not appear to work in schema files. Is this correct? Is there another
way to get at this data?


A W3C XML schema is XML and can therefore certainly be processed by a
W3C XSLT stylesheet and there you can use
<xsl:value-of select="elementname" />
to get the string value of an element with name 'elementname'.

It is not clear to me what you are asking about, do you have a W3C XML
schema and want to process that with an XSLT stylesheet? Inside of such
a schema an element is defined as follows e.g.
<xs:element name="elementname" type="xs:string" />
so an XSLT stylesheet could then go and read out
<xsl:value-of
xmlns:xs="http://www.w3.org/2001/XMLSchema"
select="xs:element/@name" />
If the element has complex content then its declaration looks like e.g.
<xs:element name="elementname">
<xs:complexType>
<xs:sequence>
<xs:element name="element2name" />
</xs:sequence>
</xs:complexType>
</xs:element>
then of course a stylesheet trying to process that needs to make sure it
processes subelements like complexType or sequence.
But as I am not sure what you are looking for it is not possible to give
a concrete example.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
"Porthos" <ja*****@vt.edu> writes:
Hi All,

I've been working on mining data from a schema file (all attribute
data so far) and have come to the point where I need to get information
that is contained in tags. For instance, <tag>My Data Here</tag>.
Note "My Data Here" is not contained in any tag (that's essentially the
definition of being data rather than markup) XSLT doesn't have access to
the tags in the original source file. It's _between_ the start tag and
end tag (each of which contain the element type name "tag").
I've tried using the <xsl:value-of select="tag"/> element, but it does
not appear to work in schema files. Is this correct? Is there another
way to get at this data?


A schema file is just a normal XML file as far as XSLT is concerned
there are no special rules at all. However two guesses as to what might
be wrong:

if you are using unprefixed element names such as
<xsl:value-of select="element"/>
then this matches element in no-namespace and you need to match element
in the namespace http://www.w3.org/2001/XMLSchema so you need
<xsl:value-of select="xs:element"/>
together with xmlns:xs="http://www.w3.org/2001/XMLSchema" on your
xsl:stylesheet.

secondly rather few xsd elements have character data content, they
almost all have element content with data being in attributes, for any
such element xsl:value-of will always return the empty string as
it just gives the character data of any descendent element of an
element node.

So you might want for example

<xsl:value-of select="xs:element/@ref"/>

to pull out a ref attribute.

David
Jul 20 '05 #3
Martin,

I have a custom XML schema (.xsd file) and want to process that with
XSLT stylesheet. The schema contains <annotation> tags of the
following general format:

<xsd:schema ...>
<annotation>
<appinfo>
<mytag1>Human Readable Information 1</mytag1>
<mytag2>Human Readable Information 2</mytag2>
</appinfo>
</annotation>
Jul 20 '05 #4
I assumed that since the schema document is an XML document
itself, I could use <xsl:value-of select="mytag1"/>


If the default namespace in your schema file is no-namespace and the
current node at that point in your stylesheet is the xs:appinfo node
then <xsl:value-of select="mytag1"/> will produce
Human Readable Information 1

so if that isn't happening either the element mytag1 isn't in
no-namespace or the current node is not xs:appinfo, but you haven't
shown enough context to guess which.

David
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Markus Ernst | last post: by
1 post views Thread by ruthless@poczta.onet.pl | last post: by
reply views Thread by Vika Zafrin | last post: by
4 posts views Thread by james.eaton@gmail.com | last post: by
2 posts views Thread by gregmcmullinjr@gmail.com | last post: by
2 posts views Thread by Rami | last post: by
3 posts views Thread by Michael | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.