Loading ...
Sorry, an error occurred while loading the content.

How can I allow one or more elements from a set without duplication?

Expand Messages
  • Klotz, Leigh
    I d like to require one, but allow up to all, of a set of elements but prohibit more than one occurrence of any individual element. For example, with elements
    Message 1 of 6 , Dec 9, 2009
    • 0 Attachment
      I'd like to require one, but allow up to all, of a set of elements but prohibit more than one occurrence of any individual element.

      For example, with elements a, b, and c being one-of required, is there a better way to express it than this?

      data = element data { (a|b|c) | (a&b) | (b&c) | (a&b&c) }

      Thank you,
      Leigh.
    • John Cowan
      ... a? & b? & c? is almost your friend here. That interleaves in arbitrary order three streams, each containing either a single element or nothing. Since you
      Message 2 of 6 , Dec 9, 2009
      • 0 Attachment
        Klotz, Leigh scripsit:

        > I'd like to require one, but allow up to all, of a set of elements
        > but prohibit more than one occurrence of any individual element.
        >
        > For example, with elements a, b, and c being one-of required, is there
        > a better way to express it than this?

        a? & b? & c? is almost your friend here. That interleaves in arbitrary
        order three streams, each containing either a single element or nothing.
        Since you want to require at least one element, you can write (a & b? &
        c?) | (a? & b & c?) | (a? & b? & c), which grows no faster than O(n^2)
        rather than O(2^n).

        --
        John Cowan cowan@... http://ccil.org/~cowan
        You cannot enter here. Go back to the abyss prepared for you! Go back!
        Fall into the nothingness that awaits you and your Master. Go! --Gandalf
      • Syd Bauman
        I don t know that it is better in any sense of the word, but I find the following a little clearer to read. data = element data { ( a & b? & c? ) | ( a? & b
        Message 3 of 6 , Dec 9, 2009
        • 0 Attachment
          I don't know that it is "better" in any sense of the word, but I find
          the following a little clearer to read.

          data = element data {
          ( a & b? & c? ) | ( a? & b & c? ) | ( a? & b? & c )
          }

          However, what I actually tend to use is

          data = element data {
          a? & b? & c?
          }

          with the additional test:

          <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">
          <sch:pattern>
          <sch:rule context="Leigh">
          <sch:assert test="a|b|c">A "Leigh" element should have a child "a", "b", or "c".</sch:assert>
          </sch:rule>
          </sch:pattern>
          </sch:schema>

          > I'd like to require one, but allow up to all, of a set of elements
          > but prohibit more than one occurrence of any individual element.
          >
          > For example, with elements a, b, and c being one-of required, is
          > there a better way to express it than this?
          >
          > data = element data { (a|b|c) | (a&b) | (b&c) | (a&b&c) }
          >
          > Thank you,
          > Leigh.
        • G. Ken Holman
          ... Would this be more clear? data = element data { (a & b? & c? ) | ( a? & b & c? ) | (a? & b? & c) } . . . . . Ken -- XSLT/XQuery/XPath training after
          Message 4 of 6 , Dec 9, 2009
          • 0 Attachment
            At 2009-12-09 15:11 -0800, Klotz, Leigh wrote:
            >I'd like to require one, but allow up to all, of a set of elements
            >but prohibit more than one occurrence of any individual element.
            >
            >For example, with elements a, b, and c being one-of required, is
            >there a better way to express it than this?
            >
            >data = element data { (a|b|c) | (a&b) | (b&c) | (a&b&c) }

            Would this be more clear?

            data = element data { (a & b? & c? ) | ( a? & b & c? ) | (a? & b? & c) }

            . . . . . Ken

            --
            XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
            Vote for your XML training: http://www.CraneSoftwrights.com/r/i/
            Crane Softwrights Ltd. http://www.CraneSoftwrights.com/r/
            Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
            Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
            Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
            G. Ken Holman mailto:gkholman@...
            Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/r/bc
            Legal business disclaimers: http://www.CraneSoftwrights.com/legal
          • Syd Bauman
            Sorry, fixed: data = element data { ( a & b? & c? ) | ( a? & b & c? ) | ( a? & b? & c ) }
            Message 5 of 6 , Dec 9, 2009
            • 0 Attachment
              Sorry, fixed:

              data = element data {
              ( a & b? & c? ) | ( a? & b & c? ) | ( a? & b? & c )
              }


              <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">
              <sch:pattern>
              <sch:rule context="data">
              <sch:assert test="a|b|c">A "data" element should have a child "a", "b", or "c".</sch:assert>
              </sch:rule>
              </sch:pattern>
              </sch:schema>
            • Klotz, Leigh
              Thank you and thanks for not pointing out the missed enumerations in my expanded example. Leigh. ... From: rng-users@yahoogroups.com
              Message 6 of 6 , Dec 9, 2009
              • 0 Attachment
                Thank you and thanks for not pointing out the missed enumerations in my expanded example.
                Leigh.

                -----Original Message-----
                From: rng-users@yahoogroups.com [mailto:rng-users@yahoogroups.com] On Behalf Of John Cowan
                Sent: Wednesday, December 09, 2009 4:15 PM
                To: rng-users@yahoogroups.com
                Subject: Re: [rng-users] How can I allow one or more elements from a set without duplication?

                Klotz, Leigh scripsit:

                > I'd like to require one, but allow up to all, of a set of elements but
                > prohibit more than one occurrence of any individual element.
                >
                > For example, with elements a, b, and c being one-of required, is there
                > a better way to express it than this?

                a? & b? & c? is almost your friend here. That interleaves in arbitrary order three streams, each containing either a single element or nothing.
                Since you want to require at least one element, you can write (a & b? &
                c?) | (a? & b & c?) | (a? & b? & c), which grows no faster than O(n^2) rather than O(2^n).

                --
                John Cowan cowan@... http://ccil.org/~cowan
                You cannot enter here. Go back to the abyss prepared for you! Go back!
                Fall into the nothingness that awaits you and your Master. Go! --Gandalf


                ------------------------------------

                Yahoo! Groups Links
              Your message has been successfully submitted and would be delivered to recipients shortly.