Re: navigate with xpath in .xsd file

  • Thread starter C. M. Sperberg-McQueen
  • Start date
C

C. M. Sperberg-McQueen

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

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top