Extracting Data from Schema Tags

P

Porthos

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
 
M

Martin Honnen

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.
 
D

David Carlisle

Porthos said:
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
 
P

Porthos

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>
 
D

David Carlisle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top