XSd problem,...

M

mavis

If I want to assign different value to different versions as the
followings:

<versions>
<version>
<name> a20 </name>
<value> 10 </value>
</version>

<version>
<name> b40 </name>
<value> 50 </value>
</version>

<version>
<name> others</name>
<value> 5 </value>
</version>
</versions>

I guess it cannot be simplified as below, even if we can use <xs:choice
maxOccurs="unbounded"> to define elements in any order with any
occurrences.. the problem is we cannot identify corresponding value for
each version...

<versions>
<version> a20 </version>
<value> 10 </value>

<version> b40 </version>
<value> 50 <value>

<version> others </version>
<value> 5 </value>
</versions>

Am I right? Could anyone confirm me about this if possible?
Thanks a lot!
 
G

George Bina

Hi,

You can define a sequence in the schema and specify the name and value
inside that sequence, then set the occurances on the sequence to handle
more versions, like below for instance:

<xs:element name="versions">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="version"/>
<xs:element name="value"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Getting the value for a version element should be easy, in XSLT for
instance if you match on a version element the the value is given by
the following XPath expression (assuming the document is valid against
the schema)

following-sibling::*[1]

Best Regards,
George
 
M

mavis

Thanks a lot!!!
Will I get problem if I need to access different values through XPath?
/versions/version/ ? /versions/value?
how can I get corresponding value for each version?
Mavis
 
G

George Bina

Hi Mavis,

If you reach a version element then the corresponding value is
following-sibling::*[1].

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Thanks a lot!!!
Will I get problem if I need to access different values through XPath?
/versions/version/ ? /versions/value?
how can I get corresponding value for each version?
Mavis

George said:
Hi,

You can define a sequence in the schema and specify the name and value
inside that sequence, then set the occurances on the sequence to handle
more versions, like below for instance:

<xs:element name="versions">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="version"/>
<xs:element name="value"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Getting the value for a version element should be easy, in XSLT for
instance if you match on a version element the the value is given by
the following XPath expression (assuming the document is valid against
the schema)

following-sibling::*[1]

Best Regards,
George
 
M

mavis

Thanks a lot. George.

George said:
Hi Mavis,

If you reach a version element then the corresponding value is
following-sibling::*[1].

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Thanks a lot!!!
Will I get problem if I need to access different values through XPath?
/versions/version/ ? /versions/value?
how can I get corresponding value for each version?
Mavis

George said:
Hi,

You can define a sequence in the schema and specify the name and value
inside that sequence, then set the occurances on the sequence to handle
more versions, like below for instance:

<xs:element name="versions">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="version"/>
<xs:element name="value"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Getting the value for a version element should be easy, in XSLT for
instance if you match on a version element the the value is given by
the following XPath expression (assuming the document is valid against
the schema)

following-sibling::*[1]

Best Regards,
George
 

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

Forum statistics

Threads
474,002
Messages
2,570,260
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top