[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Issue with repetition of elements in the input XML

Subject: Re: Issue with repetition of elements in the input XML
From: lakshmi mrudula <mrudula_lakshmi@xxxxxxxxx>
Date: Mon, 26 Nov 2007 22:17:58 +1300 (NZDT)
Re:  Issue with repetition of elements in the input XML
Hi Thanks for the updates.

But the problem with the given approach was at the end
if any element is missing then its showing empty tag.
That should not be there. I have already mentioned the
requirement in the previous mail. Structure of the
component should not change. If one or two elements
are missing at the end, even if they were not present
that doesnt make any difference. But if first element
is missing and second element is present means if we
dont give an empty tag complete structure will change.

And another problem is if CompanyId tag itself is
missing then complete that repetition information will
be missed. This can happen as none of the elements
inside the component are mandatory.


--- Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:

> Please try this:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                         version="2.0">
> 
>  <xsl:output method="xml" indent="yes" />
> 
>  <xsl:variable name="controlInfo">
>    <CompanyId/>
>    <ReservationControlNumber/>
>    <ReservationControlType/>
>    <FirstDate/>
>    <Time/>
>  </xsl:variable>
> 
>  <xsl:template match="/root">
>    <root>
>      <RCI>
>        <xsl:for-each-group
> select="ReservationControlInformationSegment/*"
> group-starting-with="CompanyId">
> 
>          <xsl:variable
> name="aReservationControlInformation">RCI<xsl:number
>                        value="position()"
> format="01"/>
>          </xsl:variable>
>          <xsl:element
> name="{$aReservationControlInformation}">
>            <xsl:for-each select="$controlInfo/*">
>               <xsl:variable
> name="aReservationControlInformationNew">
>                  <xsl:value-of
> select="$aReservationControlInformation"
> /><xsl:number
>                            value="position()"
> format="01"/>
>               </xsl:variable>
>               <xsl:element
> name="{$aReservationControlInformationNew}">
>                 <xsl:value-of
> select="current-group()[local-name() =
> local-name(current())]" />
>               </xsl:element>
>            </xsl:for-each>
>          </xsl:element>
>        </xsl:for-each-group>
>      </RCI>
>    </root>
>  </xsl:template>
> 
> </xsl:stylesheet>
> 
> On Nov 23, 2007 10:57 AM, lakshmi mrudula
> <mrudula_lakshmi@xxxxxxxxx> wrote:
> > Hi,
> >
> > Thanks for your solution.
> > But with XSL logic below,
> > If input XML is as shown below:
> >
> > <?xml version="1.0"?>
> > <root>
> >        <ReservationControlInformationSegment>
> >                <CompanyId>AAH</CompanyId>
> >
> >
>
<ReservationControlNumber>ABC12345</ReservationControlNumber>
> >               
> <ReservationControlType>A</ReservationControlType>
> >                <FirstDate>11OCT2007</FirstDate>
> >                <Time>1230</Time>
> >                <CompanyId>AAA</CompanyId>
> >
> >               
> <ReservationControlType>B</ReservationControlType>
> >                <FirstDate>11OCT2007</FirstDate>
> >                <Time>1130</Time>
> >        </ReservationControlInformationSegment>
> > </root>
> >
> > Then Expected output will be:
> >
> > <?xml version='1.0' ?>
> > <root>
> >  <RCI>
> >    <RCI01>
> >      <RCI0101>AAH</RCI0101>
> >      <RCI0102>ABC12345</RCI0102>
> >      <RCI0103>A</RCI0103>
> >      <RCI0104>11OCT2007</RCI0104>
> >      <RCI0105>1230</RCI0105>
> >    </RCI01>
> >    <RCI02>
> >      <RCI0201>AAA</RCI0201>
> >      <RCI0202/>
> >      <RCI0203>B</RCI0203>
> >      <RCI0204>11OCT2007</RCI0204>
> >      <RCI0205>1130</RCI0205>
> >    </RCI02>
> >  </RCI>
> > </root>
> >
> > But the actual output is coming with the given XSL
> as
> > below:
> >
> > <?xml version='1.0' ?>
> > <root>
> >  <RCI>
> >    <RCI01>
> >      <RCI0101>AAH</RCI0101>
> >      <RCI0102>ABC12345</RCI0102>
> >      <RCI0103>A</RCI0103>
> >      <RCI0104>11OCT2007</RCI0104>
> >      <RCI0105>1230</RCI0105>
> >    </RCI01>
> >    <RCI02>
> >      <RCI0201>AAA</RCI0201>
> >      <RCI0202>B</RCI0202>
> >      <RCI0203>11OCT2007</RCI0203>
> >      <RCI0204>1130</RCI0204>
> >    </RCI02>
> >  </RCI>
> > </root>
> >
> >
> > Our requirement for the output is:
> >
> >  If any information is missing in the middle then
> > empty
> >  tag should be there.
> >  But if it is missing at the end, then empty tags
> need
> >  not be there in the output.
> >
> >  In input XML, elements will be in the same order.
> > None
> >  of the elements are mandatory.
> >  Any of the elements can be missed in the input
> XML.
> >
> >  For this requirement we need solution.
> >
> >
> >
> >
> > --- Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
> >
> > > This problem is easily solved with the XSLT 2.0
> > > grouping construct.
> > > Please refer to the solution below:
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <xsl:stylesheet
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > >                        version="2.0">
> > >
> > >   <xsl:output method="xml" indent="yes" />
> > >
> > >   <xsl:template match="/root">
> > >     <root>
> > >       <RCI>
> > >         <xsl:for-each-group
> > > select="ReservationControlInformationSegment/*"
> > > group-starting-with="CompanyId">
> > >           <xsl:variable
> > >
> name="aReservationControlInformation">RCI<xsl:number
> > >                         value="position()"
> > > format="01"/>
> > >           </xsl:variable>
> > >           <xsl:element
> > > name="{$aReservationControlInformation}">
> > >             <xsl:for-each
> select="current-group()">
> > >                <xsl:variable
> > > name="aReservationControlInformationNew">
> > >                   <xsl:value-of
> > > select="$aReservationControlInformation"
> > > /><xsl:number
> > >                               value="position()"
> > > format="01"/>
> > >                </xsl:variable>
> > >                <xsl:element
> > > name="{$aReservationControlInformationNew}">
> > >                  <xsl:value-of select="." />
> > >                </xsl:element>
> > >             </xsl:for-each>
> > >           </xsl:element>
> > >         </xsl:for-each-group>
> > >       </RCI>
> > >     </root>
> > >   </xsl:template>
> > >
> > > </xsl:stylesheet>
> > >
> > > On Nov 22, 2007 3:05 PM, lakshmi mrudula
> > > <mrudula_lakshmi@xxxxxxxxx> wrote:
> 
=== message truncated ===


Send instant messages to your online friends http://au.messenger.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.