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 July 3rd, 2007, 04:13 PM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml2graph yet again

Hello,

I'm really really new at XSLT, I need to permorm a transformation and despite my few readings, I'm really getting confused...

To be clear, I need to convert :

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2007-05-25T20:41:06">
<SITES>
<SITE_INFORMATION>
<FECD_ID>18</FECD_ID>
<ESTABLISHMENT_DATE>1994</ESTABLISHMENT_DATE>
<TERRESTRIAL_ECOZONE>Boreal Shield</TERRESTRIAL_ECOZONE>
<BIOMASS_CARBON>
<TOTAL_TREE_CARBON>54.31</TOTAL_TREE_CARBON>
</BIOMASS_CARBON>
</SITE_INFORMATION>
</SITES>

Into :

<tree>
 <declarations>
   <attributeDecl name="name" type="String"/>
   <attributeDecl name="number" type="integer"/>
 </declarations>
 <branch>
  <attribute name="name" value="SITES"/>
  <branch>
   <attribute name="name" value="SITES_INFORMATION"/>
   <leaf>
    <attribute name="name" value="FECD_ID"/>
    <attribute name="number" value="18"/>
   </leaf>
   <leaf>
    <attribute name="name" value="ESTABLISHMENT_DATE"/>
    <attribute name="number" value="1994"/>
   </leaf>
   <leaf>
    <attribute name="name" value="TERRESTRIAL_ECOZONE"/>
    <attribute name="name" value="Boreal Shield"/>
   </leaf>
   <branch>
    <attribute name="name" value="BIOMASS_CARBON"/>
    <leaf>
     <attribute name="name" value="TOTAL_TREE_CARBON"/>
     <attribute name="number" value="54.31"/>
    </leaf>
   </branch>
  </branch>
 </branch>
</tree>

And I don't really know where to start... I one of you can put me on the right track, I'd appreciate it very much :)

Cheers!

 
Old July 4th, 2007, 02:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not sure where all the information in your output is supposed to come from, but generating the leaf elements seems to be:

<xsl:template match="SITE_INFORMATION/*">
  <leaf>
    <attribute name="name" value="{name()}"/>
    <attribute name="value" value="{.}"/>
  </leaf>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 4th, 2007, 07:59 AM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, thanks a lot!
This is the tricky thing, the value "18" in the output :

   <leaf>
    <attribute name="name" value="FECD_ID"/>
    <attribute name="number" value="18"/>
   </leaf>

is supposed to come from there <FECD_ID>18</FECD_ID>

This is probably what's tricky about it :(

But I'll try your solution in a few minutes! CHEERS!

;)










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