Connecting Tech Pros Worldwide Forums | Help | Site Map

XSL Grouping/Headers Help Needed.

Newbie
 
Join Date: Aug 2006
Posts: 1
#1: Aug 1 '06
I'm at a total loss here, I need to create an XSL template for an XML file I have, and can't seem to figure out how to get it finished. I would appreciate any help someone can provide.

I have an xml document and the it's made up like this:

Expand|Select|Wrap|Line Numbers
  1. <Catalogue>
  2.     <ProdID>1</ProdID>
  3.     <ProdDescription>Bristol Fixture HP Sodium</ProdDescription>
  4.     <ProdPartNo>AP-0207</ProdPartNo>
  5.     <ProdTypeID>3</ProdTypeID>
  6.     <ProdTypeDescription>Ornamental</ProdTypeDescription>
  7.     <ProdCatID>2</ProdCatID>
  8.     <ProdCatDescription>Lighting Fixtures</ProdCatDescription>
  9.     <ProdSubCatID>4</ProdSubCatID>
  10.     <ProdSubCatDescription>Bristol Series Fixtures</ProdSubCatDescription>
  11.     <PDFFileName>O2-Renaissance Fixture.pdf</PDFFileName>
  12. </Catalogue>
  13.  
I need it to write out a header for each distinct ProdCatID and then under that, a header for each ProdSubCatID with the appropriate ProdPartNo listed under the sub categories.

I have gotten it to the point where I can get the first categories to list with each entry under them, but can't get the second to work.

Here's the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.     <!-- consider all ProdCatDescription, one by one, sorted, no double -->
  3.     <xsl:for-each select="/NewDataSet/Catalogue/ProdCatDescription[not(../preceding-sibling::Catalogue/ProdCatDescription = .)]">
  4.         <xsl:sort/>
  5.         <xsl:call-template name="handle-ProdCatDescription">
  6.             <xsl:with-param name="ProdCatDescription" select="."/>
  7.         </xsl:call-template>
  8.     </xsl:for-each>
  9. </xsl:template>
  10.  
  11. <!-- display all ProdCatDescription for a give Catalogue -->
  12. <xsl:template name="handle-ProdCatDescription">
  13.     <xsl:param name="ProdCatDescription"/>
  14.     <xsl:variable name="Catalogues" select="/NewDataSet/Catalogue[ProdCatDescription = $ProdCatDescription]"/>
  15.     <H3>
  16.     <xsl:value-of select="$ProdCatDescription"/>, contains <xsl:value-of select="count($Catalogues)"/> Products.
  17.     </H3>
  18.     <xsl:for-each select="$Catalogues">
  19.         <xsl:sort select="ProdSubCatDescription"/>
  20.         <xsl:sort select="ProdPartNo"/>
  21.  
  22.         <xsl:value-of select="ProdSubCatDescription"/> :: <xsl:value-of select="ProdPartNo"/>
  23.         <br/>
  24.     </xsl:for-each>
  25. </xsl:template>
  26.  
This results in:

Expand|Select|Wrap|Line Numbers
  1. Main Category Name 1
  2.     Sub Category Name 1 :: Product Part Number
  3.     Sub Category Name 1 :: Product Part Number
  4.     Sub Category Name 2 :: Product Part Number
  5.  
  6. Main Category Name 2...etc...
I need it to look like this, if the Sub Category Names are the same...

Expand|Select|Wrap|Line Numbers
  1. Main Category Name 1
  2.     Sub Category Name 1
  3.         Product Part Number
  4.         Product Part Number
  5.     Sub Category Name 2
  6.         Product Part Number
  7.  
  8. Main Category Name 2...etc...
I need this done and am at a complete end, any help is much appreciated. Thanks a ton.
Member
 
Join Date: Aug 2006
Location: USA
Posts: 92
#2: Aug 11 '06

re: XSL Grouping/Headers Help Needed.


Dont be upset, we have a tool to create schemas called styluss. Go through the link below.

http://www.stylusstudio.com/videos/x...mlschema1.html
Reply