xsl-list
[Top] [All Lists]

RE: Re: XSL to write XML tag values in columns

2003-12-23 16:11:08
Sorry.. but I forgot to tell 2 things:

1) That XML was only an example. The orifinal XML will be dynamic... so f_key 
may have value 1, 2 or n.

2) This is the right structure I want to achieve:

<table>
  <tr>
    <td>f_key = 1</td>
    <td>f_key = 2</td>
  </tr>
  <tr>
    <td>blabla</td>
    <td>blibli</td>
  </tr>
  <tr>
    <td>bleble</td>
    <td>bloblo</td>
  </tr>
</table>

That HTML produces this output:

f_key = 1  f_key = 2
blabla     blibli
bleble     bloblo

Thanks
Jaime

-----Mensaje original-----
De: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]En nombre de 
Dimitre
Novatchev
Enviado el: Martes, 23 de Diciembre de 2003 17:01
Para: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Asunto: [xsl] Re: XSL to write XML tag values in columns



"Jaime Alejandro Stuardo Bahamonde" <jstuardo(_at_)security(_dot_)cl> 
wrote in message
news:CA4A243A1C219949AABAEBF59C313C3D3AB9E7(_at_)srv-security-53(_dot_)(_dot_)(_dot_)
Hi all..

I have an XML like this:

<test>
  <ROW>
    <f_key>1</f_key>
    <field>blabla</field>
  </ROW>
  <ROW>
    <f_key>1</f_key>
    <field>bleble</field>
  </ROW>
  <ROW>
    <f_key>2</f_key>
    <field>blibli</field>
  </ROW>
  <ROW>
    <f_key>2</f_key>
    <field>bloblo</field>
  </ROW>
</test>

I want that to be shown this way:

1           2
blabla     blibli
bleble     bloblo

Using muenchian method I could achieve:

1           2
blabla     bleble
blibli     bloblo

what I was not wanting.

Long time ago someone suggested me a way to do it and it 
worked, by using
mode="row" in XSL but I don't remember exactly how can I use it.


This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:output method="text"/>

  <xsl:key name="kValByField" match="field"
       use="preceding-sibling::f_key[1]"/>

  <xsl:template match="/">
    <xsl:value-of select="concat('   1','&#09;','   2','&#xA;')"/>

    <xsl:call-template name="twoColTable">
      <xsl:with-param name="pCol1" select="key('kValByField', '1')"/>
      <xsl:with-param name="pCol2" select="key('kValByField', '2')"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="twoColTable">
    <xsl:param name="pCol1" select="/.."/>
    <xsl:param name="pCol2" select="/.."/>

    <xsl:variable name="vnumCol1" select="count($pCol1)"/>
    <xsl:variable name="vnumCol2" select="count($pCol2)"/>

    <xsl:variable name="vLongerCol"
     select="$pCol1[last() > $vnumCol2]
            |
             $pCol2[last() >= $vnumCol1]"/>


    <xsl:for-each select="$vLongerCol">
      <xsl:variable name="vPos" select="position()"/>
      <xsl:value-of select="concat($pCol1[position() = $vPos],
                                   '&#09;',
                                   $pCol2[position() = $vPos],
                                   '&#xA;'
                                   )"/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

when applied on this source.xml:

<test>
  <ROW>
    <f_key>1</f_key>
    <field>blabla</field>
  </ROW>
  <ROW>
    <f_key>1</f_key>
    <field>bleble</field>
  </ROW>
  <ROW>
    <f_key>2</f_key>
    <field>blibli</field>
  </ROW>
  <ROW>
    <f_key>2</f_key>
    <field>bloblo</field>
  </ROW>
  <ROW>
    <f_key>1</f_key>
    <field>bleubleu</field>
  </ROW>
</test>

produces the wanted result:

   1    2
blabla blibli
bleble bloblo
bleubleu



Dimitre Novatchev.
FXSL developer

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>