[xsl] Re: XML transformation using XSL - Urgent, Please HELP!! Thanks

Subject: [xsl] Re: XML transformation using XSL - Urgent, Please HELP!! Thanks
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Fri, 27 Apr 2001 23:14:38 -0700 (PDT)
You probably should drop xml-dev (that list is for arguing about
xml) and post your questions to xsl-list only.

I isn't clear what pattern your ellipses continue:

<PRODUCTS>
 <PRODUCT xml:lang="en">
  <PRODUCTID>1234</PRODUCTID>     
  <MANUFACTURERCOMPANYID>1m1</MANUFACTURERCOMPANYID>
  <MANUFACTURERCOMPANYNAME>Manufactorer name</MANUFACTURERCOMPANYNAME>
  <PRODUCTQUALIFIER>MK</PRODUCTQUALIFIER>

  <MANUFACTURERCOMPANYNAME2>Manufactorer name2</MANUFACTURERCOMPANYNAME2>
  ....
  ...
  ..
  ..
 </PRODUCT>
</PRODUCTS>

However, my guess is that you have some type of repeating 'row' consisting
of fields but without the row as a containing element. In other words, with
regard to the missing "rows" your XML looks like this:

<root>
 <a>1</a> <b>apple</b>  <c>$1.29</c>
 <a>2</a> <b>cherry</b> <c>$1.69</c>
 <a>3</a> <b>grape</b>  <c>$1.15</c>
</root>

instead of this:

<root>
 <row> <a>1</a> <b>apple</b>  <c>$1.29</c> </row>
 <row> <a>2</a> <b>cherry</b> <c>$1.69</c> </row>
 <row> <a>3</a> <b>grape</b>  <c>$1.15</c> </row>
</root>

in which case it is best to use position() and modulo to address
children of PRODUCTS. So you should be able to apply the technique
demonstrated with the enclosed XML and XSL.

Regards,

Dan

-----------------
File: NoRecordsOnlyFields.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="NoRecordsOnlyFields.xsl"?>

<root>
 <a>1</a> <b>apple</b>  <c>$1.29</c>
 <a>2</a> <b>cherry</b> <c>$1.69</c>
 <a>3</a> <b>grape</b>  <c>$1.15</c>
</root>

#File: NoRecordsOnlyFields.xsl<?xml version="1.0"?>

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   
 <xsl:output indent="yes"/>
 <xsl:param name="n"/>
 
  <xsl:template match="/">
   <xsl:apply-templates select="root"/>
  </xsl:template>
   
 <xsl:template match="root">
  <xsl:copy>
   <xsl:for-each select="*[position() mod $n = 1]">
    <record>
    <xsl:for-each select=".|following-sibling::*[position() &lt; $n]">
     <xsl:copy-of select="."/>
    </xsl:for-each>
    </record>
   </xsl:for-each>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

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


Current Thread