Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use a XSL Transformation pipeline or two-stage transformation
    primarykey
    data
    text
    <p>I am trying to change one all-encompassing xsl stylesheet into a two phase stylesheet setup, where xml is translated into "ideal" xml in the first step, and the second step is merely formatting.</p> <p>Initially, we have this xml (extraneous parts removed)</p> <pre><code>&lt;?xml-stylesheet type="text/xsl" href="xsl/storeFinancialReport.xsl" ?&gt; &lt;storeFinancialReport&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz1&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing1&lt;/ProductGroup&gt;&lt;Quantity&gt;0.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;0.000000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;30.700000&lt;/SalesExcl&gt;&lt;Sales&gt;35.000000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz2&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing2&lt;/ProductGroup&gt;&lt;Quantity&gt;13.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;0.000000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;1480.970000&lt;/SalesExcl&gt;&lt;Sales&gt;1688.310000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz3&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing3&lt;/ProductGroup&gt;&lt;Quantity&gt;2.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;0.000000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;50.730000&lt;/SalesExcl&gt;&lt;Sales&gt;57.830000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz4&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing4&lt;/ProductGroup&gt;&lt;Quantity&gt;2.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;0.000000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;40.450000&lt;/SalesExcl&gt;&lt;Sales&gt;46.110000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz5&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing5&lt;/ProductGroup&gt;&lt;Quantity&gt;2.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;1.000000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;18.000000&lt;/SalesExcl&gt;&lt;Sales&gt;18.000000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;ProductGroupEntry&gt;&lt;ProductGroupCode&gt;xz6&lt;/ProductGroupCode&gt;&lt;ProductGroup&gt;thing6&lt;/ProductGroup&gt;&lt;Quantity&gt;4.0000&lt;/Quantity&gt;&lt;DiscountExcl&gt;10.080000&lt;/DiscountExcl&gt;&lt;SalesExcl&gt;62.900000&lt;/SalesExcl&gt;&lt;Sales&gt;68.420000&lt;/Sales&gt;&lt;/ProductGroupEntry&gt; &lt;/storeFinancialReport&gt; </code></pre> <p>I'm now trying to create a separate template that does the translation, sums, calculations etc that can be reused, and then just have the html formatting in a second template in a main file that imports the file with the "Enrichment/idealising" template</p> <p>So far, then, I have the below which in theory calls a template which will do the sums etc, stores this in a variable, and then this newly transformed xml as passed as a variable to the template that does the HTML formatting.</p> <p><em>Main/HTML Formatting file</em></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:set="http://exslt.org/sets" extension-element-prefixes="set"&gt; &lt;xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" /&gt; &lt;xsl:include href="scrap_book_enrichment.xsl" /&gt; &lt;!-- call Product Group Block --&gt; &lt;xsl:template name="ProductGroupBlock"&gt; &lt;xsl:variable name="buildProductGroupResultXml"&gt; &lt;!-- store the results of this template call to this variable --&gt; &lt;xsl:call-template name="buildProductGroup"&gt; &lt;xsl:with-param name="buildProductGroupResults" select="//storeFinancialReport"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;xsl:call-template name="displayProductGroupResults"&gt; &lt;xsl:with-param name="buildProductGroupResults2" select="$buildProductGroupResultXml" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="displayProductGroupResults"&gt; &lt;xsl:param name="buildProductGroupResults2" /&gt; &lt;xsl:for-each select="buildProductGroup"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:value-of select="/" /&gt; &lt;/td&gt; &lt;td colspan="3"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupCodeText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupQuantityText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupDiscountExclText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupSalesExclText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupSalesText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupSalesMinusSalesExclText/text()" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$buildProductGroupResults2/ProductGroupSalesExclPercentage/text()" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><em>Second imported file, that creates "ideal" xml</em></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:set="http://exslt.org/sets" extension-element-prefixes="set"&gt; &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt; &lt;xsl:template name="buildProductGroup"&gt; &lt;xsl:param name="buildProductGroupResults" /&gt; &lt;xsl:for-each select="set:distinct($buildProductGroupResults/ProductGroupEntry/ProductGroup)"&gt; &lt;xsl:variable name="ProductGroup"&gt; &lt;xsl:value-of select="text()" /&gt; &lt;/xsl:variable&gt; &lt;buildProductGroup&gt; &lt;ProductGroupCodeText&gt;&lt;xsl:value-of select="$buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../ProductGroupCode/text()" /&gt;&lt;xsl:text&gt; - &lt;/xsl:text&gt;&lt;xsl:value-of select="$ProductGroup" /&gt;&lt;/ProductGroupCodeText&gt; &lt;ProductGroupQuantityText&gt;&lt;xsl:value-of select="format-number(sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../Quantity/text()), '0')" /&gt; &lt;/ProductGroupQuantityText&gt; &lt;ProductGroupDiscountExclText&gt;&lt;xsl:value-of select="format-number(sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../DiscountExcl/text()), '###,##0.00')" /&gt; &lt;/ProductGroupDiscountExclText&gt; &lt;ProductGroupSalesExclText&gt;&lt;xsl:value-of select="format-number(sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../SalesExcl/text()), '###,##0.00')" /&gt; &lt;/ProductGroupSalesExclText&gt; &lt;ProductGroupSalesText&gt;&lt;xsl:value-of select="format-number(sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../Sales/text()), '###,##0.00')" /&gt; &lt;/ProductGroupSalesText&gt; &lt;ProductGroupSalesMinusSalesExclText&gt;&lt;xsl:value-of select="format-number(sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../Sales/text()) - sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../SalesExcl/text()),'###,##0.00')" /&gt; &lt;/ProductGroupSalesMinusSalesExclText&gt; &lt;ProductGroupSalesExclPercentage&gt; &lt;xsl:choose&gt; &lt;xsl:when test="sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../SalesExcl)=0"&gt; &lt;xsl:text&gt;0.00&lt;/xsl:text&gt; &lt;/xsl:when&gt; &lt;xsl:when test="sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../SalesExcl)!=0"&gt; &lt;xsl:value-of select="format-number(number(( sum($buildProductGroupResults/ProductGroup[text()=$ProductGroup]/../SalesExcl) div (sum( $buildProductGroupResults/SalesExcl ) ) ) * 100), '###,##0.00')" /&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;xsl:text&gt;%&lt;/xsl:text&gt; &lt;/ProductGroupSalesExclPercentage&gt; &lt;/buildProductGroup&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I realise these are quite chunky, but I believe I've reduced it down as much as I can whilst keeping it real to what I need. We have a dozen or more sections like this, but I'm obviously missing a fundamental step to get this to work.</p> <p>The intention is for the "enrichment" phase to create a different xml, what I've seen referred to as "ideal" xml for the formatting xsl to deal with. Unfortunately, it seems that when I run these files through the translator in eclipse it just mashes up the original xml and removes all formatting and clumps it together in a piece of text. There are probably several idea's I've misinterpreted here, but once I have this one section down, I imagine the others will fall into line a lot easier.</p> <p>Many thanks</p> <p>Mitch.</p> <p>[ UPDATED 2013/08/06 ]</p> <p>Due to the time spent unable to complete this, and the benefits we would gain in other areas, it has been decided to take the time to enable our reporting framework to inherently deal with pipelining xsls. As such, needing this functionality in one stylesheet is no longer a requirement.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload