Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: navigate with xpath in .xsd file

Thread Tools

Re: navigate with xpath in .xsd file

C. M. Sperberg-McQueen
Posts: n/a
      07-02-2003 Removed) (Michael Kleen) writes:

> hello,
> i have a .xsd file with looks like
> ?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlnss="">
> <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"
> xmlnssl="">
> <xslutput 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>
> </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"

<xslutput indent="yes" method="text"/>
<xsl:template match="/">
<xsl:value-of select="@name"/>

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

$ schema.xsd sample.xsl

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM