[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to get elements in a row?

Subject: RE: How to get elements in a row?
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 10:57:35 -0000
xsl get element
Hi,

Try this piece of xslt from a fellow newbie:

<xsl:template match="item">
  <xsl:value-of select="ancestor::sample/name"/>
  <xsl:text>, </xsl:text>
  <xsl:value-of select="name"/>
  <xsl:for-each select="features/feature">
    <xsl:text>, </xsl:text>
    <xsl:value-of select="name"/>
  </xsl:for-each>
  <br/>
</xsl:template>

<xsl:template match="/">
  <xsl:apply-templates select="//items/item"/>
</xsl:template>

produces:

sample1, item1, one, two
sample1, item2, three, four

There will be other better solutions, but this should help

cheers

andrew

===

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
Marko.Seppala@xxxxxxxx
Sent: Thursday, January 17, 2002 10:20 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  How to get elements in a row?


Hi, 

How I can get elements in a comma separated row without last comma and
header line?
Each item should have its features (one, two, three, four) but also its
parent (sample1).
I am using xalan java processor 2.2.d13.

Wanted Output
******************************************************
sample1,item1,one,two
sample1,item2,three,four
******************************************************

Current Output
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
sample1,
item1,
one,
two,
item2,
three,
four,
******************************************************

XML
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<samples>
    <sample id = "1">
        <name>sample1</name>
        <items>
            <item id = "1">
                <name>item1</name>
                <features>
                    <feature id = "1">
                        <name>one</name>
                    </feature>
                    <feature id = "2">
                        <name>two</name>
                    </feature>
                </features>
            </item>
            <item id = "12">
                <name>item2</name>
                <features>
                    <feature id = "3">
                        <name>three</name>
                    </feature>
                    <feature id = "4">
                        <name>four</name>
                    </feature>
                </features>
            </item>
        </items>
    </sample>
</samples>
******************************************************

XSL
******************************************************
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="samples"> 
<xsl:apply-templates select="sample"/>
</xsl:template>

<xsl:template match="sample"> 
<xsl:apply-templates select = "name"/>
<xsl:apply-templates select = "items"/>
</xsl:template>

<xsl:template match="items"> 
<xsl:apply-templates select="item"/>
</xsl:template>

<xsl:template match="item"> 
<xsl:apply-templates select = "name"/>
<xsl:apply-templates select = "features"/>
</xsl:template>

<xsl:template match="features"> 
<xsl:apply-templates select="feature"/>
</xsl:template>

<xsl:template match="feature"> 
<xsl:apply-templates select = "name"/>
</xsl:template>

<xsl:template match="name"> 
<xsl:value-of select = "."/>,
</xsl:template>

</xsl:stylesheet>
******************************************************

Thanks in advance!

Marko

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.