xsl-list
[Top] [All Lists]

Re: can restructure xml??

2003-01-15 05:28:17
You could do simple things like
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/>
    <xsl:template match="/">
        <root>
            <list>
                   <xsl:for-each select="/root/list/title">
                    <item num = "{position()}">
                        <title>
                            <xsl:value-of select="."/>
                        </title>
                        <writer>
                            <xsl:value-of
select="following-sibling::writer"/>
                        </writer>
                        <type>
                            <xsl:value-of select="following-sibling::type"/>
                        </type>
                        <remark>
                            <xsl:value-of
select="following-sibling::remark"/>
                        </remark>
                    </item>
                </xsl:for-each>
            </list>
        </root>
    </xsl:template>
</xsl:stylesheet>
this gets first writer,type and remark elements after each title element and
puts them under the item element. The number attribute takes the value of
the position() function. so the number of <item> elements you would have
will be the number of  <title> element you have.
But as Jarno suggested, you could as well modify the code that generates the
XML to produce the right kind of structure
Hope this helps
Vasu
-- Original Message -----
From: "a847356549/mail.h7.dion.ne.jp" 
<motom(_at_)h7(_dot_)dion(_dot_)ne(_dot_)jp>
To: <XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, January 15, 2003 11:32 AM
Subject: [xsl] can restructure xml??


hello.
I just started putting my data into xml.
now I only have a xml like ---

<root>
  <list>
    <title>aaa</title>
    <writer>bbb</writer>
    <type>ccc</type>
    <remark>ddd</remark>
    <title>eee</title>
    <writer>fff</writer>
    <type>ggg</type>
    <remark>hhh</remark>
    ...
  </cd>
</list>

my ideal structure is like ---

<root>
  <list>
   <item num="1">
    <title>aaa</title>
    <writer>bbb</writer>
    <type>ccc</type>
    <remark>ddd</remark>
   </item>
   <item num="2">
    <title>eee</title>
    <writer>fff</writer>
    <type>ggg</type>
    <remark>hhh</remark>
   </item>
    ...
  </list>
</root>

is there a way to do this throgh xsl?  any advice and hint will
 be grateful.

ttkaya

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


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



<Prev in Thread] Current Thread [Next in Thread>