danalario Posted April 21, 2010 Share Posted April 21, 2010 I've got a working XSLT for my XML output from Crystal Reports, but the XSLT its producing some strange output followed by the correct XML I want.Here's the XSLT <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:rt="urn:crystal-reports:schemas:report-detail" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="rt:CrystalReport/rt:ReportFooter/rt:Section[@SectionNumber='0']/rt:CrossTab[@Name='CrossTab1']/rt:Cells"> <xsl:for-each select="rt:Cell"> <xsl:element name="ObtmActivity"> <xsl:attribute name="FILE_ID"><xsl:value-of select="rt:CellValue[@Index='0']/rt:Value"/></xsl:attribute> <xsl:attribute name="FILE_DT"><xsl:value-of select="rt:CellValue[@Index='1']/rt:Value"/></xsl:attribute> <xsl:attribute name="SRC_CD"><xsl:value-of select="rt:CellValue[@Index='2']/rt:Value"/></xsl:attribute> <xsl:attribute name="CPKO_ID"><xsl:value-of select="rt:CellValue[@Index='3']/rt:Value"/></xsl:attribute> <xsl:attribute name="PROJ_START_DT"><xsl:value-of select="rt:CellValue[@Index='4']/rt:Value"/></xsl:attribute> <xsl:attribute name="PROJ_END_DT"><xsl:value-of select="rt:CellValue[@Index='5']/rt:Value"/></xsl:attribute> <xsl:attribute name="ACTUAL_START_DT"><xsl:value-of select="rt:CellValue[@Index='6']/rt:Value"/></xsl:attribute> <xsl:attribute name="ACTUAL_END_DT"><xsl:value-of select="rt:CellValue[@Index='7']/rt:Value"/></xsl:attribute> <xsl:attribute name="SALES_GOAL"><xsl:value-of select="rt:CellValue[@Index='8']/rt:Value"/></xsl:attribute> <xsl:attribute name="SALES_TO_DATE"><xsl:value-of select="rt:CellValue[@Index='9']/rt:Value"/></xsl:attribute> <xsl:attribute name="PROJ_ADD_SALES"><xsl:value-of select="rt:CellValue[@Index='10']/rt:Value"/></xsl:attribute> <xsl:attribute name="HOURS"><xsl:value-of select="rt:CellValue[@Index='11']/rt:Value"/></xsl:attribute> <xsl:attribute name="BEG_UNIVERSE"><xsl:value-of select="rt:CellValue[@Index='12']/rt:Value"/></xsl:attribute> <xsl:attribute name="CONTACT_CNT"><xsl:value-of select="rt:CellValue[@Index='13']/rt:Value"/></xsl:attribute> <xsl:attribute name="NON_CONTACT_CNT"><xsl:value-of select="rt:CellValue[@Index='14']/rt:Value"/></xsl:attribute> <xsl:attribute name="ACTUAL_SALES_CNT"><xsl:value-of select="rt:CellValue[@Index='15']/rt:Value"/></xsl:attribute> <xsl:attribute name="VENDOR_HRLY_RATE"><xsl:value-of select="rt:CellValue[@Index='16']/rt:Value"/></xsl:attribute> <xsl:attribute name="BUDGET"><xsl:value-of select="rt:CellValue[@Index='17']/rt:Value"/></xsl:attribute> <xsl:attribute name="FILTER_SALES_CNT"><xsl:value-of select="rt:CellValue[@Index='18']/rt:Value"/></xsl:attribute> <xsl:attribute name="CLEANCAF_SALES_CNT"><xsl:value-of select="rt:CellValue[@Index='19']/rt:Value"/></xsl:attribute> <xsl:attribute name="UPSELL1_CNT"><xsl:value-of select="rt:CellValue[@Index='20']/rt:Value"/></xsl:attribute> <xsl:attribute name="UPSELL2_CNT"><xsl:value-of select="rt:CellValue[@Index='21']/rt:Value"/></xsl:attribute> <xsl:attribute name="DELAYED_SALES_CNT"><xsl:value-of select="rt:CellValue[@Index='22']/rt:Value"/></xsl:attribute> <xsl:attribute name="DNC_CNT"><xsl:value-of select="rt:CellValue[@Index='23']/rt:Value"/></xsl:attribute> <xsl:attribute name="RESPONDER_CNT"><xsl:value-of select="rt:CellValue[@Index='24']/rt:Value"/></xsl:attribute> <xsl:attribute name="OPT_OUT_CNT"><xsl:value-of select="rt:CellValue[@Index='25']/rt:Value"/></xsl:attribute> <xsl:attribute name="LEADS_CNT"><xsl:value-of select="rt:CellValue[@Index='26']/rt:Value"/></xsl:attribute> </xsl:element> </xsl:for-each> </xsl:template></xsl:stylesheet> Here's the XML. Excuse the length and mess of this file please...Its generated from Crystal Reports and it just sort of horks everything out however it likes. <?xml version="1.0" encoding="UTF-8" ?><CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:crystal-reports:schemas:report-detail [url="http://www.businessobjects.com/products/xml/CR2008Schema.xsd">"]http://www.businessobjects.com/products/xm...a.xsd">[/url]<ReportFooter><Section SectionNumber="0"><CrossTab Name="CrossTab1"><RowGroups><RowGroup><RowTotal RowNumber="0"></RowTotal></RowGroup></RowGroups><ColumnGroups><ColumnGroup><ColumnGroup><ColumnTotal ColumnNumber="0">301</ColumnTotal><ColumnTotal ColumnNumber="1">302</ColumnTotal><ColumnTotal ColumnNumber="2">303</ColumnTotal><ColumnTotal ColumnNumber="3">304</ColumnTotal><ColumnTotal ColumnNumber="4">305</ColumnTotal><ColumnTotal ColumnNumber="5">306</ColumnTotal><ColumnTotal ColumnNumber="6">31T</ColumnTotal></ColumnGroup></ColumnGroup></ColumnGroups><SummaryFieldLabels><SummaryFieldLabel RowNumber="0" Index="0">@FILE_ID</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="1">@FILE_DT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="2">@SRC_CD</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="3">@CPKO_ID</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="4">@PROJ_START_DT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="5">@PROJ_END_DT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="6">@ACTUAL_START_DT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="7">@ACTUAL_END_DT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="8">@SALES_GOAL</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="9">@SALES_TO_DATE</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="10">@PROJ_ADD_SALES</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="11">@HOURS</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="12">@BEG_UNIVERSE</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="13">@CONTACT_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="14">@NON_CONTACT_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="15">@ACTUAL_SALES_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="16">@VENDOR_HRLY_RATE</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="17">@BUDGET</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="18">@FILTER_SALES_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="19">@CLEANCAF_SALE_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="20">@UPSELL1_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="21">@UPSELL2_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="22">@DELAYED_SALES_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="23">@DNC_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="24">@RESPONDER_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="25">@OPT_OUT_CNT</SummaryFieldLabel><SummaryFieldLabel RowNumber="0" Index="26">@LEADS_CNT</SummaryFieldLabel></SummaryFieldLabels><Cells><Cell RowNumber="0" ColumnNumber="0"><CellValue Index="0"><FormattedValue>00000000021</FormattedValue><Value>00000000021</Value></CellValue><CellValue Index="1"><FormattedValue>2010-04-17</FormattedValue><Value>2010-04-17</Value></CellValue><CellValue Index="2"><FormattedValue>PTPM</FormattedValue><Value>PTPM</Value></CellValue><CellValue Index="3"><FormattedValue>301</FormattedValue><Value>301</Value></CellValue><CellValue Index="4"><FormattedValue>2010-03-15</FormattedValue><Value>2010-03-15</Value></CellValue><CellValue Index="5"><FormattedValue>2010-05-15</FormattedValue><Value>2010-05-15</Value></CellValue><CellValue Index="6"><FormattedValue>2010-04-01</FormattedValue><Value>2010-04-01</Value></CellValue><CellValue Index="7"><FormattedValue>2010-04-20</FormattedValue><Value>2010-04-20</Value></CellValue><CellValue Index="8"><FormattedValue>8500</FormattedValue><Value>8500</Value></CellValue><CellValue Index="9"><FormattedValue>59.00</FormattedValue><Value>59.00</Value></CellValue><CellValue Index="10"><FormattedValue>356</FormattedValue><Value>356</Value></CellValue><CellValue Index="11"><FormattedValue>8</FormattedValue><Value>8</Value></CellValue><CellValue Index="12"><FormattedValue>15,423</FormattedValue><Value>15,423</Value></CellValue><CellValue Index="13"><FormattedValue>70</FormattedValue><Value>70.00</Value></CellValue><CellValue Index="14"><FormattedValue>29.00</FormattedValue><Value>29.00</Value></CellValue><CellValue Index="15"><FormattedValue>18</FormattedValue><Value>18.00</Value></CellValue><CellValue Index="16"><FormattedValue>24.00</FormattedValue><Value>24.00</Value></CellValue><CellValue Index="17"><FormattedValue>115000.00</FormattedValue><Value>115000.00</Value></CellValue><CellValue Index="18"><FormattedValue>4</FormattedValue><Value>4.00</Value></CellValue><CellValue Index="19"><FormattedValue>2</FormattedValue><Value>2.00</Value></CellValue><CellValue Index="20"><FormattedValue>3</FormattedValue><Value>3.00</Value></CellValue><CellValue Index="21"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="22"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="23"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="24"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="25"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="26"><FormattedValue>99</FormattedValue><Value>99.00</Value></CellValue></Cell><Cell RowNumber="0" ColumnNumber="1"><CellValue Index="0"><FormattedValue>00000000021</FormattedValue><Value>00000000021</Value></CellValue><CellValue Index="1"><FormattedValue>2010-04-17</FormattedValue><Value>2010-04-17</Value></CellValue><CellValue Index="2"><FormattedValue>PTPM</FormattedValue><Value>PTPM</Value></CellValue><CellValue Index="3"><FormattedValue>302</FormattedValue><Value>302</Value></CellValue><CellValue Index="4"><FormattedValue>2010-03-15</FormattedValue><Value>2010-03-15</Value></CellValue><CellValue Index="5"><FormattedValue>2010-05-15</FormattedValue><Value>2010-05-15</Value></CellValue><CellValue Index="6"><FormattedValue>2010-04-01</FormattedValue><Value>2010-04-01</Value></CellValue><CellValue Index="7"><FormattedValue>2010-04-20</FormattedValue><Value>2010-04-20</Value></CellValue><CellValue Index="8"><FormattedValue>8500</FormattedValue><Value>8500</Value></CellValue><CellValue Index="9"><FormattedValue>59.00</FormattedValue><Value>59.00</Value></CellValue><CellValue Index="10"><FormattedValue>356</FormattedValue><Value>356</Value></CellValue><CellValue Index="11"><FormattedValue>5.2</FormattedValue><Value>5.2</Value></CellValue><CellValue Index="12"><FormattedValue>22,855</FormattedValue><Value>22,855</Value></CellValue><CellValue Index="13"><FormattedValue>142</FormattedValue><Value>142.00</Value></CellValue><CellValue Index="14"><FormattedValue>12.00</FormattedValue><Value>12.00</Value></CellValue><CellValue Index="15"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue><CellValue Index="16"><FormattedValue>24.00</FormattedValue><Value>24.00</Value></CellValue><CellValue Index="17"><FormattedValue>115000.00</FormattedValue><Value>115000.00</Value></CellValue><CellValue Index="18"></CellValue><CellValue Index="19"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="20"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="21"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="22"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="23"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="24"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="25"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue><CellValue Index="26"><FormattedValue>154</FormattedValue><Value>154.00</Value></CellValue></Cell></Cells></CrossTab></Section></ReportFooter></CrystalReport> Here's what I get for output. <?xml version="1.0" encoding="UTF-8"?>[color="#FF0000"]30130230330430530631T@FILE_ID@FILE_DT@SRC_CD@CPKO_ID@PROJ_START_DT@PROJ_END_DT@ACTUAL_START_DT@ACTUAL_END_DT@SALES_GOAL@SALES_TO_DATE@PROJ_ADD_SALES@HOURS@BEG_UNIVERSE@CONTACT_CNT@NON_CONTACT_CNT@ACTUAL_SALES_CNT@VENDOR_HRLY_RATE@BUDGET@FILTER_SALES_CNT@CLEANCAF_SALE_CNT@UPSELL1_CNT@UPSELL2_CNT@DELAYED_SALES_CNT@DNC_CNT@RESPONDER_CNT@OPT_OUT_CNT@LEADS_CNT[/color]<ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="301" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="8" BEG_UNIVERSE="15,423" CONTACT_CNT="70.00" NON_CONTACT_CNT="29.00" ACTUAL_SALES_CNT="18.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="4.00" CLEANCAF_SALES_CNT="2.00" UPSELL1_CNT="3.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="99.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="302" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="5.2" BEG_UNIVERSE="22,855" CONTACT_CNT="142.00" NON_CONTACT_CNT="12.00" ACTUAL_SALES_CNT="10.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="" CLEANCAF_SALES_CNT="0.00" UPSELL1_CNT="0.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="154.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="303" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="6" BEG_UNIVERSE="1,717" CONTACT_CNT="6.00" NON_CONTACT_CNT="1.00" ACTUAL_SALES_CNT="2.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="" CLEANCAF_SALES_CNT="0.00" UPSELL1_CNT="1.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="7.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="304" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="10.3" BEG_UNIVERSE="4,781" CONTACT_CNT="39.00" NON_CONTACT_CNT="1.00" ACTUAL_SALES_CNT="5.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="3.00" CLEANCAF_SALES_CNT="1.00" UPSELL1_CNT="1.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="40.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="305" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="0" BEG_UNIVERSE="2,540" CONTACT_CNT="10.00" NON_CONTACT_CNT="0.00" ACTUAL_SALES_CNT="1.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="1.00" CLEANCAF_SALES_CNT="1.00" UPSELL1_CNT="0.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="10.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="306" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="0" BEG_UNIVERSE="1,218" CONTACT_CNT="6.00" NON_CONTACT_CNT="0.00" ACTUAL_SALES_CNT="2.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="" CLEANCAF_SALES_CNT="0.00" UPSELL1_CNT="0.00" UPSELL2_CNT="0.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="6.00"/><ObtmActivity FILE_ID="00000000021" FILE_DT="2010-04-17" SRC_CD="PTPM" CPKO_ID="31T" PROJ_START_DT="2010-03-15" PROJ_END_DT="2010-05-15" ACTUAL_START_DT="2010-04-01" ACTUAL_END_DT="2010-04-20" SALES_GOAL="8500" SALES_TO_DATE="59.00" PROJ_ADD_SALES="356" HOURS="0" BEG_UNIVERSE="15,422" CONTACT_CNT="67.00" NON_CONTACT_CNT="27.00" ACTUAL_SALES_CNT="21.00" VENDOR_HRLY_RATE="24.00" BUDGET="115000.00" FILTER_SALES_CNT="4.00" CLEANCAF_SALES_CNT="1.00" UPSELL1_CNT="4.00" UPSELL2_CNT="1.00" DELAYED_SALES_CNT="0.00" DNC_CNT="0.00" RESPONDER_CNT="0.00" OPT_OUT_CNT="0.00" LEADS_CNT="94.00"/> I've highlighted in red the "Garbage" that i'm getting in this XML output that I don't want.I can see that the Garbage is coming from the <SummaryFieldLabel> and <ColumnTotal> fields from the Input XML, but I don't understand why its making it into the output XML.Aside from that "Garbage" at the top of the Output XML the remainder of the file is exactly as I want it...Why is this happening? Link to comment Share on other sites More sharing options...
Martin Honnen Posted April 22, 2010 Share Posted April 22, 2010 You have written a single template for an element deep down in the XML document. How do you expect processing of your XML to reach that element? That is because of default (or built-in) templates http://www.w3.org/TR/xslt#built-in-rule. So you exploit those templates with your approach but you also end up with unwanted output. You have two choices to avoid that problem, either add <xsl:template match="/"> <xsl:apply-templates select="rt:CrystalReport/rt:ReportFooter/rt:Section[@SectionNumber='0']/rt:CrossTab[@Name='CrossTab1']/rt:Cells"/></xsl:template> to ensure that the processing (which always starts at the root node /) then only processes the rt: Cells element you are interested in and not all child nodes recursively as the built-in templates do.Or make sure that the built-in templates for text nodes are overridden in your stylesheet with e.g. <xsl:template match="text()"/> that way the unwanted output is prevented. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.