xsl-list
[Top] [All Lists]

RE: Attribute to elements conversion, "preserving "and simplifying hierarchy, insertion of new element

2004-11-19 09:38:04
Do you want the <Row> to appear for each date?

Jeni has a great example on how to add hierarchy to a flat structure. You can 
view that here: 
http://www.biglist.com/lists/xsl-list/archives/200012/msg00175.html

From your current transform, it looks like you'll want to add the row on each 
encounter of a time element. Though your initial input file already has the 
hierarchy set up with the <Cube @time> elements...

<Cube>
<Cube @time>
   <Cube @currency/>
   <Cube @currency/>
   ...
</Cube>
</Cube>

so ideally you'd want

<Cube>
<-- INSERT <ROW>
<Cube @time>
   <Cube @currency/>
   <Cube @currency/>
   ...
</Cube>
<-- INSERT </ROW>
</Cube>

So if you could handle the case without breaking the hierarchy and then adding 
it back in that would probably be best. Just sort of seems like double work.


-----Original Message-----
From: jcastanheira(_at_)businessdecision(_dot_)com
[mailto:jcastanheira(_at_)businessdecision(_dot_)com]
Sent: Friday, November 19, 2004 10:45 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Attribute to elements conversion, "preserving "and
simplifying hierarchy, insertion of new element


Hello,
 
I've been trying to convert the following XML structure
(http://www.ecb.int/stats/eurofxref/eurofxref-hist.xml) to achieve
something like this : 
 
<?xml version="1.0" encoding="UTF-8" ?>
<EuroFxRef>
   <Row>
     <time>2004-11-19</time>
     <USD>1.302</USD>
     ....
   </Row>
     <time>2004-11-18</time> 
     <USD>1.3024</USD>
     ....
</EuroFxRef>
 
After checking the list and FAQ for similar problems (attribute to element
conversion, hierarchy, ...), I came up with the following XSL which is
close to what I'm trying to get but not quite it as I do not see how to
insert the <Row> element as shown here above:
 
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
     <xsl:output method="xml"/>
     <xsl:template match="/">
        <EuroFxRef>
           <xsl:apply-templates select="*|@*"/>
       </EuroFxRef>
     </xsl:template>
     <xsl:template match="*">
         <xsl:apply-templates select="*|@*"/>
     </xsl:template>
    <xsl:template match="@time">
        <xsl:element name="{name()}">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="@currency">
           <xsl:variable name="Thename" select="."/>
           <xsl:variable name="Therate" select="../@rate"/>
           <xsl:element name="{$Thename}">
               <xsl:value-of select="$Therate"/>
          </xsl:element>
    </xsl:template>
    <xsl:template match="@rate"/>
</xsl:stylesheet>
 
Thanks in advance,
 
João 
 

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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