0

I have the following XML:

<Pattern name="Form" Date="12/18/2015 3:25 AM CST">
  Swap_Conversion 
  <CurrentLocale /> 
  <Patterns>
    <Pattern name="Section">
      Swap_Conversion 
      <Patterns>
        <Pattern name="GroupResult" status="AUTH" inputType="19">
          Ultrasound Duration 
          <Patterns>
            <Pattern name="GridDTA">23350691</Pattern> 
            <Pattern name="GridDTA">56468381</Pattern> 
            <Pattern name="GridDTA">20218422</Pattern> 
            <Pattern name="GridDTA">21058661</Pattern> 
            <Pattern name="GridDTA">4156900</Pattern> 
            <Pattern name="GridDTA">20008930</Pattern> 
            <Pattern name="GridDTA">21197198</Pattern> 
         </Patterns>
         <Patterns>
           <Pattern name="GroupResult" status="AUTH" inputType="">
              Ear Irrigation Solution 
              <Patterns /> 
              <Patterns>
                <Pattern name="CodedResult" status="AUTH" display="Ace Bandage :" taskAssayCode="23350691">2 inch</Pattern> 
              </Patterns>
           </Pattern>
        </Patterns>
        <Patterns>
          <Pattern name="GroupResult" status="AUTH" inputType="">
            Frame Order Priority 
            <Patterns /> 
            <Patterns>
              <Pattern name="CodedResult" status="AUTH" display="Ace Bandage :" taskAssayCode="23350691">3 inch</Pattern> 
            </Patterns>
          </Pattern>
        </Patterns>
       </Pattern>
     </Patterns>
    </Pattern>
  </Patterns>
</Pattern

Currently I have the transpose which look something like:

This is the transpose of grid

But I want it to look something like:

This is without transposing

Currently I had tried with which worked for transpose:

            <xsl:choose>
          <xsl:when test="$inputType='19'"
            <xsl:variable name="groupNodeSet" select="Patterns/Pattern[@name='GroupResult']"/>
            <xsl:for-each select="$groupNodeSet[position() &lt;= ((last() + $tablecolumns - 1) div $tablecolumns)]">
              <!-- loopCount indicates which table of the multiple tables that a grid control may be split into that we are currently generating-->
              <xsl:variable name="loopCount" select="position()"/>
              <fo:table border="1pt solid black">
                <fo:table-column/>
                <fo:table-column/>
                <fo:table-column/>
                <fo:table-body>
                  <fo:table-row>
                    <fo:table-cell border-width="thin">
                      <fo:block/>
                    </fo:table-cell>
                    <fo:table-cell>
                      <xsl:if test="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 1)]">
                        <xsl:attribute name="border-width">
                          <xsl:text>thin</xsl:text>
                        </xsl:attribute>
                      </xsl:if>
                      <fo:block font-size="{$regularfontsize}" font-family="sans-serif" text-align="left" font-style="italic">
                        <xsl:value-of select="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 1)]/text()"/>
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell>
                      <xsl:if test="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 2)]">
                        <xsl:attribute name="border-width">
                          <xsl:text>thin</xsl:text>
                        </xsl:attribute>
                      </xsl:if>
                      <fo:block font-size="{$regularfontsize}" font-family="sans-serif" text-align="left" font-style="italic">
                        <xsl:value-of select="$groupNodeSet[position()=((($loopCount - 1) * $tablecolumns) + 2)]/text()"/>
                      </fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                  <xsl:for-each select="../../Patterns/Pattern[@name='GridDTA' and ../..//@taskAssayCode=text()]">
                    <xsl:variable name="taskassay">
                      <xsl:value-of select="node()"/>
                    </xsl:variable>
                    <fo:table-row>
                      <fo:table-cell border-width="thin">
                        <fo:block>
                          <xsl:value-of select="../..//Pattern/@display[../..//Pattern/@taskAssayCode=$taskassay]"/>
                        </fo:block>
                      </fo:table-cell>
                      <xsl:call-template name="GenerateGridTableCells">
                        <xsl:with-param name="count" select="1"/>
                        <xsl:with-param name="maxcount" select="$tablecolumns"/>
                        <xsl:with-param name="taskassay" select="$taskassay"/>
                        <xsl:with-param name="groupNodeSet" select="$groupNodeSet"/>
                        <xsl:with-param name="rowNumber" select="$loopCount"/>
                      </xsl:call-template>
                    </fo:table-row>
                  </xsl:for-each>
                </fo:table-body>
              </fo:table>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>

I have tried multiple approach for normal one (not the transpose) which isn't working for.

Can anyone help me in having the grid matrix without transpose for the above XML?

lfurini
  • 3,729
  • 4
  • 30
  • 48
KRS
  • 3
  • 5
  • I don't understand your question. Could you minimize the example and post the exact **code** you want as the result of the transformation? Also, the XSLT snippet you show us is useless when taken out of context. Please review: http://stackoverflow.com/help/mcve – michael.hor257k Dec 22 '15 at 14:57
  • Hello Michael, Thanks for the response. I need the dynamic transformation for the above XML so the output would be as shown in "This is without transposing" picture. We can ignore the above transformation as that is the dynamic transpose transformation for XML. – KRS Dec 23 '15 at 03:49
  • Are you using XSLT 1.0 or XSLT 2.0 (or XSLT 3.0)? It would be a lot of work in XSLT 1.0 but rather easier in XSLT 2.0. – Tony Graham Dec 23 '15 at 14:26
  • Hello Tony, I am beginner in XSLT, I appreciate your help! We're using XSLT 1.0. – KRS Dec 24 '15 at 04:51
  • Any thoughts on this? – KRS Dec 28 '15 at 04:02
  • you need to expand a description using your data. I can think of easy ways (which I am sure are not correct) to obtain that output from your input. We should not be trying to examine and determine what you are attempting to do in your current XSL. – Kevin Brown Dec 28 '15 at 05:49
  • Hello @Kevin Brown, Currently for the above XML I'm trying to get the dynamic transformation (XSLT) so the output would be as shown in "This is without transposing" picture. In addition, I'm using XSLT 1.0 version. – KRS Dec 28 '15 at 06:39
  • @Kevin, Please let me know if you need any other information. Any help is appreciated! – KRS Dec 30 '15 at 09:18

1 Answers1

0

Since you're using XSLT 1.0, you're stuck with using Meunchian grouping (muenchian grouping, http://www.jenitennison.com/xslt/grouping/muenchian.html). Using XSLT 2.0 would have made it easier.

The version below can cope with a variations in the 'CodedResult' within each 'GroupResult'.

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:variable name="regularfontsize" select="'12pt'"/>

  <xsl:output indent="yes" />

  <xsl:key name="coded-results"
           match="Pattern[@name = 'CodedResult'][@status = 'AUTH']"
           use="@display" />

  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="a">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="a">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="Pattern/Patterns/Pattern[@name = 'Section']/Patterns/Pattern" />
        </fo:flow>
      </fo:page-sequence>
    </fo:root>

  </xsl:template>

  <xsl:variable name="inputType" select="'19'" />

  <xsl:template match="Pattern[@inputType = '19']">
    <xsl:variable name="all-coded-results"
      select="Patterns/Pattern[@inputType = '']/Patterns/Pattern[@name = 'CodedResult']
                                                                       [count(. | key('coded-results', @display)[1]) = 1]" />
    <fo:table border="1pt solid black">
      <fo:table-column/>
      <xsl:for-each
          select="$all-coded-results">
        <fo:table-column/>
      </xsl:for-each>
      <fo:table-body>
        <fo:table-row>
          <fo:table-cell />
          <xsl:for-each
              select="$all-coded-results">
            <xsl:sort />
            <fo:table-cell>
              <fo:block>
                <xsl:value-of select="@display" />
              </fo:block>
            </fo:table-cell>
          </xsl:for-each>
        </fo:table-row>
        <xsl:apply-templates select="Patterns/Pattern[@name = 'GroupResult']">
          <xsl:with-param name="all-coded-results" select="$all-coded-results" />
        </xsl:apply-templates>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="Pattern[@name = 'GroupResult'][@inputType = '']">
    <xsl:param name="all-coded-results" />
    <fo:table-row>
      <fo:table-cell>
        <fo:block>
          <xsl:value-of select="normalize-space(text())" />
        </fo:block>
      </fo:table-cell>
      <xsl:variable name="this-pattern" select="." />
      <xsl:for-each
          select="$all-coded-results">
        <xsl:sort />
        <xsl:variable name="this-result" select="."/>
        <fo:table-cell>
          <xsl:if test="$this-pattern/Patterns/Pattern[@display = $this-result/@display]">
          <fo:block>
            <xsl:value-of select="$this-pattern/Patterns/Pattern[@display = $this-result/@display]" />
          </fo:block>
          </xsl:if>
        </fo:table-cell>
      </xsl:for-each>
    </fo:table-row>
  </xsl:template>
</xsl:stylesheet>
Community
  • 1
  • 1
Tony Graham
  • 7,306
  • 13
  • 20