Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2011, 02:51 PM
Registered User
 
Join Date: Oct 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble creating XSLT solution... need ideas

Hi all,

I'm having trouble coming up with the correct XSLT code and was wondering if anyone could point me in the right direction. This is what I need to do...


I've got an xml tree with pages like so:
Code:
<page>
<title>A<title>
<subtitle>I</subtitle>
<item>1</item>
</page>
<page>
<title>D<title>
<subtitle>V</subtitle>
<item>7</item>
</page>
<page>
<title>A<title>
<subtitle>II</subtitle>
<item>5</item>
</page>
<page>
<title>A<title>
<subtitle>I</subtitle>
<item>9</item>
</page>
I want to be able to write some XSL code to display the data in a nested format like so:
Code:
-A
  -I
    -1
    -9
  -II
    -5
-D
  -V
    -7
So far I'm able to select a <title> and print the <subtitle>s of all <page>s that have said <title>. However, I can't figure out how to do the two-level iteration.

Here is a snippet of my code.
Code:
<xsl:template match="/">
<xsl:apply-templates select="//page[./title[not(.=preceding::title)]]"/> 
</xsl:template>

<xsl:template match="page">
<xsl:variable name="fac"><xsl:value-of select=".//title"/></xsl:variable>
 <ul>
    <xsl:for-each select="//page[title = $fac]">
       <li>..print out sub-title...</li>
    </xsl:for-each>
 </ul>
</xsl:template>
 
Old October 18th, 2011, 04:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This appears to be a grouping problem. Something like:

Code:
<xsl:for-each-group select="page" group-by="title">
  <div class="title"><xsl:value-of select="current-grouping-key()"/></div>
  <xsl:for-each-group select="current-group()" group-by="subtitle">
     <div class="subtitle"><xsl:value-of select="current-grouping-key()"/></div>
     <xsl:for-each select="current-group()">
        <div class="item"><xsl:value-of select="./></div>
     </
  </
</
That's XSLT 2.0 of course - if you want a 1.0 solution, you'll have to learn about Muenchian grouping.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Any ideas on creating IMs using WCF maricar BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 July 16th, 2010 04:04 AM
Creating The Project In VS2008 - Directory for Solution? vigorniensis BOOK: Professional DotNetNuke Module Programming ISBN: 978-0-470-17116-5 0 April 12th, 2010 11:39 PM
VB Project Solution Ideas? snufse General .NET 5 December 10th, 2007 11:34 AM
SOLUTION - Creating an 'integer' only textbox dparsons C# 5 January 25th, 2007 01:31 PM
trouble creating array Tachyon Beginning PHP 3 June 28th, 2004 11:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.