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 September 7th, 2006, 04:31 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Node Processing

Hi, I have an XML source document that ressembles the following structure.

<testsuite>
    <testcase classname="x">
        ...
    </testcase>
        .
        .
        .
    <testcase classname="z">
        ...
    </testcase>
        .
        .
        .
</testsuite>

What I need to do is create an html table for each
testcase with the same value for their classname attribute.

So in the example above, I'll have 2 html tables, 1 for all those
testcases with classname="x" and 1 for all those testcases with classname="z".

I'm having problems keeping track of things due to the fact I'm not used to working with XSLT variables. My initial thought was to use a series of if statements, however I came across problems because I was looking to open tables in one IF and close them in another, the XSLT processor then complained that I hadn't closed certain tags.

Could somebody please give me a rough outline of what they feel might be an appropriate structure for this transform.

Thanks.
 
Old September 7th, 2006, 04:38 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Take a look at Muenchian grouping, if you're using XSLT 1.0. If using version 2.0 you can use the native features, xsl:for-each-group.
http://www.jenitennison.com/xslt/gro...muenchian.html

--

Joe (Microsoft MVP - XML)
 
Old September 7th, 2006, 04:52 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So if I use <xsl:for-each-group select="testcase" group-by="testcase/@classname">

will this run once for each different classname that it finds?

 
Old September 7th, 2006, 04:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The problem is known as "grouping".

Grouping is much easier in XSLT 2.0 by using <xsl:for-each-group>.

For 1.0 solutions (one might say workarounds) see http://www.jenitennison.com/xslt/grouping, or any XSLT textbook.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 7th, 2006, 04:56 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The group-by expression is relative to the selected elements, so you don't want to repeat "testcase" in the path.

Yes, the body of the for-each-group is processed once for each distinct value of the grouping key. Within the body, you can access the contents of the group using the current-group() function.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 7th, 2006, 05:20 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could I also ask. I'm looking to also transform this same source to pdf. Is there an xslt-fo processor I can use that uses saxon or some other xslt 2.0 compliant processor?
 
Old September 7th, 2006, 05:42 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry just answered my own question.

Just incase anyone every looks for an answer in future -
I converted to xml to fo in saxon >temp.fo - then I converted from fo to pdf in Apache FOP.






Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Missing Node (Node data) pashworth XSLT 3 January 29th, 2007 12:39 PM
Processing first node in a sequence djmarquette XSLT 3 November 15th, 2005 01:05 PM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





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