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 28th, 2012, 06:44 AM
Registered User
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT for getting all node values

Hi,
I have a XML like
<code>
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<section>
<name>sec1</name>
<description>sec1desc</description>
<sections>
<name>secs1</name>
<description>secs1desc</description>
<item>
<name>item1</name>
<description>item1desc</description>
<items>
<name>items1</name>
<description>items1desc</description>
<value>
<name>value1</name>
<description>value1desc</description>
</value>
</items>
</item>
</sections>
<sections>
<name>secs2</name>
<description>secs2desc</description>
<item>
<name>item2</name>
<description>item2desc</description>
<items>
<name>items1</name>
<description>items1desc</description>
<value>
<name>value1</name>
<description>value1desc</description>
</value>
</items>
<items>
<name>items2</name>
<description>items2desc</description>
<value>
<name>value1</name>
<description>value1desc</description>
</value>
</items>
</item>

</sections>
</section>
</root>
</code>

section/sections/item/items/value/values - all have <name>,<description> element. it is some what similiar to 1 to many. I need get all name, description value in the below format
section -- will be multiple within root
sections - will be mltiple within section
item , items, value and values - all are 1 to many

For each section i need to display its childrend nodes values like

section 1
sections1
item1
item2
.........
sections2
item1
item2
value1
==================
section 2
sections1
item1
item2
.........
sections2
item1
item2
value1
===============
my xsl
<code>
<xsl:for-each select="root/section">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="description" /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="root/section/sections">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="description" /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="root/section/sections/item">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="description" /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="root/section/sections/item/items">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="description" /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="root/section/sections/item/items/value">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="description" /></td>
</tr>
</xsl:for-each>
</code>
this is listing all the sections in one go like

Name Description
-------------------
sec1 sec1desc
secs1 secs1desc
secs2 secs2desc
item1 item1desc
item2 item2desc
items1 items1desc
items1 items1desc
items2 items2desc
value1 value1desc
value1 value1desc
value1 value1desc

please help with xslt to group elements within node.
 
Old October 28th, 2012, 07:01 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please let us know whether you use an XSLT 2.0 processor or an XSLT 1.0 processor.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 28th, 2012, 08:22 AM
Registered User
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Needed in both xslt 2.0 and xslt 1.0

hi,
Need to have them in both.
Thanks & regards,
Balaji.T.S
 
Old October 28th, 2012, 08:45 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

It is difficult to understand what you want to achieve as the input sample you posted contains names like "sec1" and "secs1", yet your result sample contains different names (like "section 1"). Also your input sample already appears to be grouped, with that structure it looks as if simply doing
Code:
<xsl:for-each select="root/section">
  <xsl:for-each select="sections/item">
    <xsl:for-each select="items">
    ...
might suffice to output the structure you have.
If that does not help then consider to post a result sample matching the input sample you have posted, and please make sure you use http://p2p.wrox.com/misc.php?do=bbcode#code to properly mark up code samples.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 28th, 2012, 09:13 AM
Registered User
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display section

Hi,
I have under root various section each contains sections and each sections contains item and each item contains items. It is like 1 to many and all of them have <name>some name</name> and <description>some description</description> element in them.
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
    <section>
        <name>sec1</name>
        <description>sec1desc</description>
        <sections>
            <name>secs1</name>
            <description>secs1desc</description>
            <item>
                <name>item1</name>
                <description>item1desc</description>
                <items>
                    <name>items1</name>
                    <description>items1desc</description>
                    <value>
                        <name>value1</name>
                       <description>value1desc</description>
                    </value>
                </items>
            </item>
        </sections>
        <sections>
            <name>secs2</name>
            <description>secs2desc</description>
             <item>
                <name>item2</name>
                <description>item2desc</description>
                <items>
                    <name>items1</name>
                    <description>items1desc</description>
                    <value>
                        <name>value1</name>
                       <description>value1desc</description>
                    </value>
                </items>
                     <items>
                    <name>items2</name>
                    <description>items2desc</description>
                    <value>
                        <name>value1</name>
                       <description>value1desc</description>
                    </value>
                </items>
            </item>

        </sections>
</section>
</root>
using xslt i need an output in html table like this
HTML Code:
<table>
<tr>
section1 name      section1 description
<hr>
sections1 name    sections1 description
item name         item description
<hr>
sections2 name sections2 description
item1 name         item1 description
<hr>
</tr>


<tr>
section2 name      section2 description
<hr>
sections1 name    sections1 description
item1 name         item1 description
<hr>
sections2 name sections2 description
item1 name         item1 description
<hr>
</tr>
</table>
The idea is to present for each section list all its siblings in a individual group
thank you
regards,
balaji.t.s





Similar Threads
Thread Thread Starter Forum Replies Last Post
List of node values, only once for multiples mphare XSLT 4 February 1st, 2008 03:09 PM
modifying a node in xslt the rail dale XSLT 3 July 17th, 2007 09:15 AM
Access the values from other node pravind XSLT 1 March 6th, 2006 07:42 AM
Accessing values from the last sibling node graywoodhouse XSLT 3 October 29th, 2004 06:15 AM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM





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