[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Reshuffling elements

Subject: Reshuffling elements
From: Morten Ryg <mort-ry@xxxxxxxxx>
Date: Tue, 26 Oct 2004 13:32:15 +0200
reshuffling
Exporting records from a Filemaker file, I get an XML file with the following structure for each record:

    <row modid="147" recordid="20">
      <col> <!-- Category -->
        <data>
          Medicine
        </data>
      </col>
      <col> <!-- Journal name -->
        <data>
          British Medical Journal
        </data>
      </col>
      <col> <!-- URL -->
        <data>
          http://bmj.bmjjournals.com/
        </data>
      </col>
      <col>
        <data>
          Fulltekstartikler tilgjengelig ved publikasjon
        </data>
      </col>
      <col> <!-- col 5: Auxiliary categories -->
        <data>
          Publisher
        </data>
        <data>
          Organisation
        </data>
      </col>
      <col> <!-- col 6: Name of auxiliary link -->
        <data>
          BMJ Publishing Group
        </data>
        <data>
          British Medical Association
        </data>
      </col>
      <col> <!-- col 7: Auxiliary URL -->
        <data>
          http://www.bmjpg.com/
        </data>
        <data>
          http://www.bma.org.uk/
        </data>
      </col>
    </row>
    
 I want to transform this into HTML in the form

 Journal title
 Link category: Link name name, URL 
 
 There can be any number of <data> elements per <col> element for col no 5 - 7, but the same number for each of these columns.

The following code produces the output I am after for data element no 1:

    <xsl:if test="./fmp:COL[6]/fmp:DATA[1] != '' ">
      <p>
        <em>
          <xsl:value-of select="fmp:COL[5]/fmp:DATA[1]" />
          <xsl:text>: </xsl:text> 
        </em>
          <xsl:value-of select="fmp:COL[6]/fmp:DATA[1]" />
          <xsl:text>, URL: </xsl:text>
          <xsl:value-of select="fmp:COL[7]/fmp:DATA[1]" />
      </p>
    </xsl:if>


British Medical Journal 
Organisation: British Medical Association, URL: http://www.bma.org.uk/
Publisher: BMJ Publishing Group, URL: http://www.bmjpg.com/


I can extend this to heart's content, by adding more blocks, and increasing the DATA[1] to DATA[2], DATA[3] and so on, but I would rather have solution for any number of auxiliary links. When I try the following;

    <xsl:for-each select="fmp:COL[6]/fmp:DATA">
      <xsl:param name="n_pos" select="position()" />
        
        <p>
        <xsl:value-of select="$n_pos" />. 
         <xsl:value-of select="." />, 
        <xsl:value-of select="../following-sibling/child[1]" /> 
        </p>
    </xsl:for-each>
    
I get the result:

British Medical Journal 

1. British Medical Association,
2. BMJ Publishing Group,

in other words, the data elemenents of col[7] are left out. 

If I modify the following-sibling line, using 
<xsl:value-of select="../following-sibling::*" />
 instead of 
 <xsl:value-of select="../following-sibling/child[1]" />,
 
I get a listing of the URLs of all auxiliary links after each auxiliary link name, as expected: 

British Medical Journal 
1. British Medical Association, http://www.bma.org.uk/http://www.bmjpg.com/
2. BMJ Publishing Group, http://www.bma.org.uk/http://www.bmjpg.com/

How can I get this right? 
-- 
***************************
Morten Ryg
Glittreklinikken
1488 Hakadal
Norway
tel: 	  +47 67058283
mobil:	      938 53 076
fax:	  +47 67075344
mail:     mort-ry@xxxxxxxxx
web       http://home.online.no/~mort-ry/
***************************

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.