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 May 4th, 2006, 06:59 PM
jz jz is offline
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I do this in XSLT?

Hi,

given the following xml fragment:

<page/>
<paragraph>
  some paragraph text
</paragraph>
<paragraph>
  more paragraph text
  <page/>
  even more paragraph text
</paragraph>

is it possible and how can I use xslt to produce this result:

<table><tr><td>
  <p> some paragraph text </p>
  <p> more paragraph text </p>
</td></tr><tr><td>
  <p> even more paragraph text </p>
</td></tr></table>


thanks,

jz

 
Old May 5th, 2006, 02:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

YOu need to explain what the rules are behind the transformation. Why does the third para go in a new table row, while the second goes in the same row as the first? Is it something to do with the empty page elements?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 5th, 2006, 08:58 AM
jz jz is offline
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, the empty page elements in the source document are essentially markers marking where a new page sits for reference purposes. The problem is some paragraphs start at the bottom of a page and finish at the top of the next page. However, I need to keep the paragraphs together in the source document.

My current thinking is that I could walk the tree with following-sibling but how do I only walk the tree as far as the next <page/> whether it is a child of a paragraph or a sibling...


 
Old May 5th, 2006, 09:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is a "positional grouping" problem. All grouping problems are best tackled using XSLT 2.0, which offers <xsl:for-each-group group-starting-with="page"> to address this need.

In 1.0 the techniques are basically:

(a) recursive traversal of the sibling axis (typically using xsl:apply-templates select="following-sibling::*[1]")

(b) treating it as a value-based grouping problem (using any of the techniques for value-based grouping) with generate-id(preceding-sibling::page[1]) as the grouping key.

Searching for "XSLT positional grouping" might help, also see http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5171e424

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 5th, 2006, 09:14 AM
jz jz is offline
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's great! thanks for the help.
jz






Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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