Re: navigate with xpath in .xsd file

Discussion in 'XML' started by C. M. Sperberg-McQueen, Jul 2, 2003.

  1. (Michael Kleen) writes:

    > hello,
    >
    > i have a .xsd file with looks like
    >
    > ?xml version="1.0" encoding="UTF-8"?>
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    > <xs:group name="ORF">
    > <xs:sequence>
    > <xs:element name="BIOLATTRIBUTES"/>
    > <xs:element name="PHYSATTRIBUTES"/>
    > <xs:element name="DESCRIPTION"/>
    > <xs:element name="INTERACTINGOBJECT"/>
    > <xs:element name="ORIGIN"/>
    > <xs:element name="name" type="xs:string"/>
    > <xs:element name="synonyms" type="xs:string"/>
    > <xs:element name="genename" type="xs:string"/>
    > <xs:element name="ID" type="xs:long"/>
    > </xs:sequence>
    > </xs:group>
    > <etc.../>
    >
    > now i want get every <xs:group> name to write it i[n?] a text file ..
    >
    > ?xml version="1.0" encoding="UTF-8"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput indent="yes" method="text"/>
    > <xsl:template match="/">
    > <xsl:for-each
    > select="//xs:schema/xs:group/@name//xs:schema/xs:group/@name">


    I'm not sure I understand this XPath expression. You appear to be
    looking for the names of xs:group elements which are children of
    xs:schema elements which are descendants of name attributes on
    xs:group elements which are children of xs:schema elements. But since
    attributes don't have element descendants, I'd expect this to return
    the empty nodeset.

    I am not sure I've fully understood your goal, but if you are trying
    to write the name of each group into a text file I would have expected
    a 'select' something more like

    <xsl:for-each select="//xs:schema/xs:group">

    In your sample solution, I also don't see a namespace declaration for
    'xs' as a namespace prefix.

    > <xsl:text>
    > class.name=
    > </xsl:text>
    > <xsl:value-of select="text()"/>


    I don't believe that attributes have text nodes as children.
    I think what you want to say here is something more like
    <xsl:value-of select="@name"/>

    > </xsl:for-each>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > but i don't get the right expression ..


    What expression do you get? If you get anything at all,
    given the XPath shown in your example, it has to be useful
    to know what you're getting.

    > it doesn't work with "//xs:schema/xs:group/@name" and it doesn't work
    > with
    > "//schema/group/@name" hiw can i navigate in a .xsd file with
    > <xs:element> tags ?


    This one works for me (modulo some cosmetic issues):

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >

    <xsl:eek:utput indent="yes" method="text"/>
    <xsl:template match="/">
    <xsl:for-each
    select="//xs:schema/xs:group[@name]">
    <xsl:text>
    class.name=
    </xsl:text>
    <xsl:value-of select="@name"/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    By 'works', I mean it produces output which I believe is what you are
    looking for:

    $ saxon.sh schema.xsd sample.xsl

    class.name=
    ORF

    I hope this helps.

    -C. M. Sperberg-McQueen
    World Wide Web Consortium
     
    C. M. Sperberg-McQueen, Jul 2, 2003
    #1
    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,109
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    493
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    864
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    794
    Peter Aberline
    Apr 5, 2004
  5. Mavis
    Replies:
    1
    Views:
    517
    =?iso-8859-1?q?Fl=E1vio_Barata?=
    Aug 8, 2006
Loading...

Share This Page