Help merging and reordering table data

Here should go questions about transforming XML with XSLT and FOP.
undrmoons
Posts: 11

Help merging and reordering table data

Mon Jun 08, 2009 4:43 pm

I have data coming form a database which contains bulleted information along with table data. I need to merge the first row of data with the bullets and other strings in a praticular order and am having trouble getting the desired result... Sample XML and the desired out put are below, along with XSL I am currently using, which is close but falling short.

Any assistance would be greatly appreciated!
-undr


************* original XML **************
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Story>
<Product_Name Hero=""> Awesome Shredder collection <Product_Image
href="file:///Volumes/Product_Images/S033xxxx/S0330xxx/S03305xx/S0330568.eps"
LetterKey="" ComfortKey="" Caption=""/><Product_Image
href="file:///Volumes/Product_Images/S032xxxx/S0329xxx/S03295xx/S0329573.eps"
LetterKey="" ComfortKey="" Caption=""/><Product_Image
href="file:///Volumes/Product_Images/S032xxxx/S0326xxx/S03260xx/S0326007.eps"
LetterKey="" ComfortKey="" Caption=""/></Product_Name>
<Subhead_First_Bullet>Auto start/stop </Subhead_First_Bullet>
<Body_Copy>Reverse function clears jams </Body_Copy>
<Body_Copy>Front-opening wastebasket </Body_Copy>
<Body_Copy>1-year mfr. limited warranty </Body_Copy>

<Table >
<Cell>
<Chart_Header_Red>SKU</Chart_Header_Red>
</Cell>
<Cell>
<Chart_Header>Offer Detail</Chart_Header>
</Cell>
<Cell>
<Chart_Header>Offer Comment</Chart_Header>
</Cell>
<Cell>
<Chart_Header>Offer Language</Chart_Header>
</Cell>
<Cell>
<Chart_Header>Reg Retail</Chart_Header>
</Cell>
<Cell>
<Chart_Header>Save Amt</Chart_Header>
</Cell>
<Cell>
<Chart_Header>AD Retail</Chart_Header>
</Cell>
<Cell >
<SKU>4463545840</SKU>
</Cell>
<Cell >
<Chart_Copy>Offer detail text from excel file</Chart_Copy>
</Cell>
<Cell >
<Chart_Copy>Offer comment text from excel file</Chart_Copy>
</Cell>
<Cell >
<Offer_Language>Offer language text input by account services</Offer_Language>
</Cell>
<Cell >
<Reg_Retail>$179.99</Reg_Retail>
</Cell>
<Cell >
<Save_Amt>$30.00</Save_Amt>
</Cell>
<Cell >
<AD_Retail>$149.99</AD_Retail>
</Cell>
<Cell >
<Chart_Subhead>6 sheet cross-cut</Chart_Subhead>
</Cell>
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell >
<SKU>4463545840</SKU>
</Cell>
<Cell >
<Chart_Copy>Offer detail text from excel file</Chart_Copy>
</Cell>
<Cell >
<Chart_Copy>Offer comment text from excel file</Chart_Copy>
</Cell>
<Cell >
<Offer_Language>Offer langauge text input by account services</Offer_Language>
</Cell>
<Cell >
<Reg_Retail>$149.99</Reg_Retail>
</Cell>
<Cell >
<Save_Amt>$20.00</Save_Amt>
</Cell>
<Cell >
<AD_Retail>$129.99</AD_Retail>
</Cell>
<Cell >
<Chart_Subhead>4 sheet cross-cut</Chart_Subhead>
</Cell>
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell />
<Cell >
<SKU>4463545840</SKU>
</Cell>
<Cell >
<Chart_Copy>Offer detail text from excel file</Chart_Copy>
</Cell>
<Cell >
<Chart_Copy>Offer comment text from excel file</Chart_Copy>
</Cell>
<Cell >
<Offer_Language>Offer langauge text input by account services</Offer_Language>
</Cell>
<Cell >
<Reg_Retail>$129.99</Reg_Retail>
</Cell>
<Cell >
<Save_Amt>$10.00</Save_Amt>
</Cell>
<Cell >
<AD_Retail>$119.99</AD_Retail>
</Cell>
</Table>
<Disclaimer> Collection disclaimer text</Disclaimer>
</Story>

******************************************
Desired output:

<?xml version="1.0" encoding="UTF-8"?>
<Story>
<AD_Retail>$149.99 </AD_Retail>
<Save_Amt> Save $30.00 </Save_Amt>
<Item_Name><Product_Image
href="file:///Volumes/Product_Images/S033xxxx/S0330xxx/S03305xx/S0330568.eps"
LetterKey="" ComfortKey="" Caption=""/><Product_Image
href="file:///Volumes/Product_Images/S032xxxx/S0329xxx/S03295xx/S0329573.eps"
LetterKey="" ComfortKey="" Caption=""/><Product_Image
href="file:///Volumes/Product_Images/S032xxxx/S0326xxx/S03260xx/S0326007.eps"
LetterKey="" ComfortKey="" Caption=""/>Collection </Item_Name>
<Item_Copy>Auto start/stop </Item_Copy>
<Item_Copy>Reverse function clears jams </Item_Copy>
<Item_Copy>Front-opening wastebasket </Item_Copy>
<Item_Copy>1-year mfr. limited warranty </Item_Copy>
<Reg_Retail>Reg. price $179.99</Reg_Retail>
<Offer_Language>Offer language text input by account services </Offer_Language>
<SKU> 4463545840 </SKU>


<Item_Name>6 sheet cross-cut</Item_Name>
<Reg_Retail>Reg. price $149.99</Reg_Retail>
<Save_Amt> Save $20.00 </Save_Amt>
<AD_Retail>$129.99 </AD_Retail>
<Offer_Language>Offer langauge text input by account services </Offer_Language>
<SKU> 4463545840 </SKU>

<Item_Name>4 sheet cross-cut</Item_Name>
<Reg_Retail>Reg. price $129.99</Reg_Retail>
<Save_Amt> Save $10.00 </Save_Amt>
<AD_Retail>$119.99 </AD_Retail>
<Offer_Language>Offer langauge text input by account services </Offer_Language>
<SKU> 4463545840 </SKU>
<Disclaimer> Collection disclaimer text</Disclaimer>
</Story>

*******************************
Current XSL I am using:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#x09;">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="Story">
<xsl:copy>
<xsl:apply-templates select="comment()"/>
<xsl:apply-templates select="AD_Retail"/>
<xsl:apply-templates select="Save_Amt"/>
<xsl:apply-templates select="Product_Name"/>
<xsl:apply-templates select="Subhead_First_Bullet"/>
<xsl:apply-templates select="Body_Copy"/>
<xsl:apply-templates select="Table"/>
<xsl:apply-templates select="Chart_Subhead"/>
<xsl:apply-templates select="Reg_Retail"/>
<xsl:apply-templates select="Offer_Language"/>
<xsl:apply-templates select="SKU"/>
<xsl:apply-templates select="Chart_Copy"/>
<xsl:apply-templates select="Disclaimer"/>

</xsl:copy>
</xsl:template>
<xsl:template match="comment()">
<xsl:copy></xsl:copy>
</xsl:template>
<xsl:template match="Product_Name">
<Item_Name>
<xsl:copy-of select="Product_Image"/>
<xsl:apply-templates/>
<xsl:copy-of select="Logo_Image_1"/>
<xsl:text>
</xsl:text>
</Item_Name>
<xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="Subhead_First_Bullet">
<Item_Copy>
<xsl:apply-templates/>
</Item_Copy>
</xsl:template>
<xsl:template match="Body_Copy">
<Item_Copy>
<xsl:apply-templates/>
</Item_Copy>
</xsl:template>

<xsl:template match="Offer_Language">
<Offer_Language>
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</Offer_Language>
</xsl:template>

<xsl:template match="SKU">
<xsl:choose>
<xsl:when test="(following::Chart_Copy[2])">
<SKU>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</SKU>
</xsl:when>
<xsl:otherwise>
<SKU>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</SKU>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="Chart_Header_Red"/>
<xsl:template match="Chart_Header"/>


<xsl:template match="AD_Retail">
<AD_Retail>
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</AD_Retail>
</xsl:template>
<xsl:template match="Reg_Retail">
<Reg_Retail>
<xsl:text>Reg. price </xsl:text>
<xsl:apply-templates/>
</Reg_Retail>
</xsl:template>
<xsl:template match="Save_Amt">
<Save_Amt>
<xsl:text> Save </xsl:text>
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</Save_Amt>
</xsl:template>

<xsl:template match="Chart_Copy"/>

<xsl:template match="Chart_Subhead">
<Item_Name>
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
</Item_Name>
</xsl:template>

<xsl:template match="Disclaimer">
<Disclaimer>
<xsl:apply-templates/>
</Disclaimer>
<xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>

******* end xsl *********


Again, thanks in advance

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests