1 Reply Latest reply: Sep 17, 2011 4:52 AM by odie_63 RSS

    Need to Divide Parameter groups using XQUERY

    886411
      Is there a way that we can divide a group in XQUERY depending upon the no. of times a particular attribute repeats ?

      I/P xml will be of format:
      <:Element>
           <SingleValue><Name>IPaddress</Name><Value>abc</Value></SingleValue>
           <SingleValue><Name>IPaddress</Name><Value>def</Value></SingleValue>
           <SingleValue><Name>IPMask</Name><Value>abc</Value></SingleValue>
           <SingleValue><Name>IPMask</Name><Value>def</Value></SingleValue>
      </:Element>

      o/p format has to be:

      <:Element>
           <:p_address1>abc</:p_address1>
           <:ip_mask1>abc</:ip_mask1>
           <:ip_address2>def</:ip_address2>
           <:ip_mask2>def</:ip_mask2>
      </:Element>
        • 1. Re: Need to Divide Parameter groups using XQUERY
          odie_63
          <:Element>
          That's an invalid element name. Did you mean to add a namespace prefix at some point?

          Anyway, assuming an input document like :
          <Element>
            <SingleValue><Name>IPaddress</Name><Value>abc</Value></SingleValue>
            <SingleValue><Name>IPaddress</Name><Value>def</Value></SingleValue>
            <SingleValue><Name>IPMask</Name><Value>abc</Value></SingleValue>
            <SingleValue><Name>IPMask</Name><Value>def</Value></SingleValue>
          </Element>
          This should do it :
          <Element> 
          {
            for $IPaddr at $p in $inputXML/Element/SingleValue[Name="IPaddress"]/Value
            return (
              element {concat("ip_address", $p)} {$IPaddr/text()}
            , element {concat("ip_mask", $p)} {$inputXML/Element/SingleValue[Name="IPMask"][$p]/Value/text()}
            )
          }
          </Element>