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 June 1st, 2007, 09:51 AM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT help!!

i have this XML:

Code:
<indexs>
    <index>
        <name>Joe</name>
        <team>ABC</team>
        <date>2000</date>
    </index>
    <index>
        <name>Joe</name>
        <team>ZXT</team>
        <date>2003</date>
    </index>
    <index>
        <name>Pete</name>
        <team>XPTO</team>
        <date>2002</date>
    </index>
</indexs>
i have a XSL file to transform:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


  <xsl:template match="/">
    <myindex>
      <xsl:apply-templates select="indexs/index/name" mode="temp1"/>
    </myindex>
  </xsl:template>


  <xsl:template match="indexs/index/name" mode="temp1">
    <name>
      <xsl:attribute name="id">
        <xsl:value-of select="node()"/>
      </xsl:attribute>
      <activity>
        <team>
          <xsl:value-of select="../team/node()"/>
        </team>
        <date>
          <xsl:value-of select="../date/node()"/>
        </date>
      </activity>
    </name>
  </xsl:template>

</xsl:stylesheet>

but my result is:

Code:
<?xml version="1.0" encoding="utf-8"?>
<myindex>
    <name id = "Joe">
        <activity>
            <team>ABC</team>
            <date>2000</date>
        </activity>
    </name>
    <name id = "Joe">
        <activity>
            <team>ZXT</team>
            <date>2003</date>
        </activity>
    </name>
    <name id = "Pete">
        <activity>
            <team>XPTO</team>
            <date>2002</date>
        </activity>
    </name>
</myindex>
and i want this result:

Code:
<myindex>
    <name id="Joe">
        <activity>
            <team>ABC</team>
            <date>2000</date>
        </activity>
        <activity>
            <team>ZXT</team>
            <date>2003</date>
        </activity>
    </name>
    <name id="Pete">
        <activity>
            <team>XPTO</team>
            <date>2002</date>
        </activity>
    </name>
<myindex>
i don´t know how to write the XPath to do this result, can you help me?

thanks
 
Old June 1st, 2007, 11:55 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 classic grouping problem. In XSLT 2.0 it's easy, use xsl:for-each-group. In XSLT 1.0 it's harder, use Muenchian grouping as described at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





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.