Extracting Data from Schema Tags

Discussion in 'XML' started by Porthos, Mar 14, 2005.

  1. Porthos

    Porthos Guest

    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
     
    Porthos, Mar 14, 2005
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Mar 14, 2005
    #2
    1. Advertising

  3. "Porthos" <> 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
     
    David Carlisle, Mar 14, 2005
    #3
  4. Porthos

    Porthos Guest

    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>
     
    Porthos, Mar 14, 2005
    #4

  5. > 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
     
    David Carlisle, Mar 14, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,545
    Markus
    Nov 23, 2005
  2. Joyce
    Replies:
    0
    Views:
    551
    Joyce
    Mar 1, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,265
    Stanimir Stamenkov
    Apr 25, 2005
  4. Damo_Suzuki
    Replies:
    1
    Views:
    325
    Damo_Suzuki
    Dec 8, 2006
  5. undbund
    Replies:
    1
    Views:
    93
Loading...

Share This Page