XSLT Transformation

J

Jens Hofmeier

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
 
M

msbalaji

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
 
J

Jens Hofmeier

Great! Thanks a lot!

msbalaji said:
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
 

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
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top