Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL:IF within XSL:for-each-group
    text
    copied!<p>In my XSLT, I have something like:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="PhyscianTotals" name="PhyscianTotals"&gt; &lt;xsl:for-each select="PhysicianTotals"&gt; &lt;xsl:for-each-group select="Statistic" group-by="Type"&gt; &lt;xsl:if test="Title='PHYSICIAN DETAIL TOTAL'"&gt; &lt;xsl:element name="totals"&gt; &lt;/xsl:element&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each-group&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Is this valid XSLT? Specifically, the section of "xsl:if within the xsl:for-each-group". One of the XSLT compilation tool we call always error out stating: xsl:if is not allowed at this position in the stylesheet. If I remove the xsl:for-each-group, it passes. I am not sure if it's my xslt having errors or if it's the compilation tool.</p> <hr> <p>Turns out our tool only support XSLT 1.0. So I guess I am back to rewrite the XSLT using 1.0 tags only.</p> <p>The original XML looks like:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;PhysicianTotals&gt; &lt;Statistic&gt; &lt;Title&gt;PHYSICIAN TOTAL&lt;/Title&gt; &lt;Type&gt;Type 1&lt;/Type&gt; &lt;Key&gt;Cases&lt;/Key&gt; &lt;Value&gt;1&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;PHYSICIAN TOTAL&lt;/Title&gt; &lt;Type&gt;Type 1&lt;/Type&gt; &lt;Key&gt;Percentage&lt;/Key&gt; &lt;Value&gt;25.0%&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;PHYSICIAN TOTAL&lt;/Title&gt; &lt;Type&gt;Type 2&lt;/Type&gt; &lt;Key&gt;Cases&lt;/Key&gt; &lt;Value&gt;3&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;PHYSICIAN TOTAL&lt;/Title&gt; &lt;Type&gt;Type 1&lt;/Type&gt; &lt;Key&gt;Percentage&lt;/Key&gt; &lt;Value&gt;75.0%&lt;/Value&gt; &lt;/Statistic&gt; &lt;/PhysicianTotals&gt; </code></pre> <p>And the output will look like:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;totals&gt; &lt;type&gt;PHY_DETAIL&lt;/type&gt; &lt;detailInfo&gt; &lt;code&gt;Type 1&lt;/code&gt; &lt;/detailInfo&gt; &lt;count&gt; &lt;caseValue&gt;1&lt;/caseValue&gt; &lt;percentValue&gt;25.0%&lt;/percentValue&gt; &lt;/count&gt; &lt;/totals&gt; &lt;totals&gt; &lt;type&gt;PHY_DETAIL&lt;/type&gt; &lt;detailInfo&gt; &lt;code&gt;Type 2&lt;/code&gt; &lt;/detailInfo&gt; &lt;count&gt; &lt;caseValue&gt;3&lt;/caseValue&gt; &lt;percentValue&gt;75.0%&lt;/percentValue&gt; &lt;/count&gt; &lt;/totals&gt; </code></pre>
 

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