XSLT Transformation

Discussion in 'XML' started by Jens Hofmeier, Jul 15, 2008.

  1. Hi,

    i am quite new to xml and need to transform an existing xml file:
    <Location>
    <ArticleDescription>
    <Description>Shirt Hawaii</Description>
    </ArticleDescription>
    <ArticleMiscs>
    <ArticleMisc>
    <Country>DEU</Country>
    <Size>32</Size>
    </ArticleMisc>
    <art:ArticleMisc>
    <Country>USA</art:Country>
    <Size>XS</art:Size>
    </ArticleMisc>
    <ArticleMisc>
    <Country>GBR</art:Country>
    <Size>6</art:Size>
    </ArticleMisc>
    </ArticleMiscs>
    </Location>

    this should be transformed to:

    <Location>
    <ArticleDescription>
    <Description>Shirt Hawaii</Description>
    </ArticleDescription>
    <ArticleMiscs>
    <ArticleMisc>
    <Country>DEU</Country>
    <Size>32</Size>
    </ArticleMisc>
    </ArticleMiscs>
    </Location>

    <Location>
    <ArticleDescription>
    <Description>Shirt Hawaii</Description>
    </ArticleDescription>
    <ArticleMiscs>
    <ArticleMisc>
    <Country>USA</art:Country>
    <Size>XS</art:Size>
    </ArticleMisc>
    </ArticleMiscs>
    </Location>

    <Location>
    <ArticleDescription>
    <Description>Shirt Hawaii</Description>
    </ArticleDescription>
    <ArticleMiscs>
    <ArticleMisc>
    <Country>GBR</art:Country>
    <Size>6</art:Size>
    </ArticleMisc>
    </ArticleMiscs>
    </Location>

    So the original file contains 3 "ArticleMisc" Sections per <Location>,
    the tranformed one only one Misc per Location. Can anybody give me a
    hint how this van be done via XSLT?

    Thanks,

    Jens
    Jens Hofmeier, Jul 15, 2008
    #1
    1. Advertising

  2. Jens Hofmeier

    msbalaji Guest

    Hi,

    try this code

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform">
    <xsl:eek:utput method="xml" indent="yes"/>
    <xsl:template match="Location">
    <xsl:for-each select="//ArticleMisc">
    <Location>
    <xsl:copy-of select="../../ArticleDescription"/>
    <ArticleMiscs>
    <xsl:copy-of select="."/>
    </ArticleMiscs>
    </Location>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    Regards,
    Balaji. M
    sql-ebooks.blogspot.com

    On Jul 15, 11:56 am, Jens Hofmeier <> wrote:
    > Hi,
    >
    > i am quite new to xml and need to transform an existing xml file:
    > <Location>
    >           <ArticleDescription>
    >             <Description>Shirt Hawaii</Description>
    >            </ArticleDescription>
    >         <ArticleMiscs>
    >           <ArticleMisc>
    >             <Country>DEU</Country>
    >             <Size>32</Size>
    >           </ArticleMisc>
    >           <art:ArticleMisc>
    >             <Country>USA</art:Country>
    >             <Size>XS</art:Size>
    >           </ArticleMisc>
    >           <ArticleMisc>
    >             <Country>GBR</art:Country>
    >             <Size>6</art:Size>
    >           </ArticleMisc>
    >          </ArticleMiscs>
    > </Location>
    >
    > this should be transformed to:
    >
    > <Location>
    >           <ArticleDescription>
    >             <Description>Shirt Hawaii</Description>
    >            </ArticleDescription>
    >         <ArticleMiscs>
    >           <ArticleMisc>
    >             <Country>DEU</Country>
    >             <Size>32</Size>
    >           </ArticleMisc>
    >        </ArticleMiscs>
    > </Location>
    >
    > <Location>
    >            <ArticleDescription>
    >             <Description>Shirt Hawaii</Description>
    >            </ArticleDescription>
    >         <ArticleMiscs>
    >            <ArticleMisc>
    >             <Country>USA</art:Country>
    >             <Size>XS</art:Size>
    >           </ArticleMisc>
    >        </ArticleMiscs>
    > </Location>
    >
    > <Location>
    >           <ArticleDescription>
    >             <Description>Shirt Hawaii</Description>
    >            </ArticleDescription>
    >         <ArticleMiscs>
    >           <ArticleMisc>
    >             <Country>GBR</art:Country>
    >             <Size>6</art:Size>
    >           </ArticleMisc>
    >        </ArticleMiscs>
    > </Location>
    >
    > So the original file contains 3 "ArticleMisc" Sections per <Location>,
    > the tranformed one only one Misc per Location. Can anybody give me a
    > hint how this van be done via XSLT?
    >
    > Thanks,
    >
    > Jens
    msbalaji, Jul 15, 2008
    #2
    1. Advertising

  3. Great! Thanks a lot!

    msbalaji <> wrote:
    > Hi,
    >
    > try this code
    >
    > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    > Transform">
    > <xsl:eek:utput method="xml" indent="yes"/>
    > <xsl:template match="Location">
    > <xsl:for-each select="//ArticleMisc">
    > <Location>
    > <xsl:copy-of select="../../ArticleDescription"/>
    > <ArticleMiscs>
    > <xsl:copy-of select="."/>
    > </ArticleMiscs>
    > </Location>
    > </xsl:for-each>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > Regards,
    > Balaji. M
    > sql-ebooks.blogspot.com
    >
    > On Jul 15, 11:56 am, Jens Hofmeier <> wrote:
    >
    > > Hi,

    >
    > > i am quite new to xml and need to transform an existing xml file:
    > > <Location>
    > >           <ArticleDescription>
    > >             <Description>Shirt Hawaii</Description>
    > >            </ArticleDescription>
    > >         <ArticleMiscs>
    > >           <ArticleMisc>
    > >             <Country>DEU</Country>
    > >             <Size>32</Size>
    > >           </ArticleMisc>
    > >           <art:ArticleMisc>
    > >             <Country>USA</art:Country>
    > >             <Size>XS</art:Size>
    > >           </ArticleMisc>
    > >           <ArticleMisc>
    > >             <Country>GBR</art:Country>
    > >             <Size>6</art:Size>
    > >           </ArticleMisc>
    > >          </ArticleMiscs>
    > > </Location>

    >
    > > this should be transformed to:

    >
    > > <Location>
    > >           <ArticleDescription>
    > >             <Description>Shirt Hawaii</Description>
    > >            </ArticleDescription>
    > >         <ArticleMiscs>
    > >           <ArticleMisc>
    > >             <Country>DEU</Country>
    > >             <Size>32</Size>
    > >           </ArticleMisc>
    > >        </ArticleMiscs>
    > > </Location>

    >
    > > <Location>
    > >            <ArticleDescription>
    > >             <Description>Shirt Hawaii</Description>
    > >            </ArticleDescription>
    > >         <ArticleMiscs>
    > >            <ArticleMisc>
    > >             <Country>USA</art:Country>
    > >             <Size>XS</art:Size>
    > >           </ArticleMisc>
    > >        </ArticleMiscs>
    > > </Location>

    >
    > > <Location>
    > >           <ArticleDescription>
    > >             <Description>Shirt Hawaii</Description>
    > >            </ArticleDescription>
    > >         <ArticleMiscs>
    > >           <ArticleMisc>
    > >             <Country>GBR</art:Country>
    > >             <Size>6</art:Size>
    > >           </ArticleMisc>
    > >        </ArticleMiscs>
    > > </Location>

    >
    > > So the original file contains 3 "ArticleMisc" Sections per <Location>,
    > > the tranformed one only one Misc per Location. Can anybody give me a
    > > hint how this van be done via XSLT?

    >
    > > Thanks,

    >
    > > Je
    Jens Hofmeier, Jul 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF0Qw==?=

    Xslt Transformation getting &lt; and &gt;

    =?Utf-8?B?UGF0Qw==?=, May 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    853
    Steven Cheng[MSFT]
    May 19, 2004
  2. clogwog
    Replies:
    0
    Views:
    415
    clogwog
    Oct 20, 2004
  3. Blue Gecko
    Replies:
    1
    Views:
    436
    Blue Gecko
    Oct 3, 2005
  4. pradeep gummi
    Replies:
    3
    Views:
    955
    pradeep gummi
    Aug 13, 2003
  5. Matt Bradbury
    Replies:
    3
    Views:
    450
    Dimitre Novatchev
    Aug 21, 2003
Loading...

Share This Page