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 November 23rd, 2011, 01:42 PM
Authorized User
 
Join Date: Nov 2011
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml to graphML conversion using xlst.

Hi, I am very new to xml and xlst, I practiced small xml file and i converted but I am not able to iterate loops or something. My xml file look like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<orderinfo>
 <data>
  <service provider>raj</service provider> 
  <Customer>bvr</Customer> 
  <Suppliers>
   <Supplier Id="svr" /> 
   <Supplier Id="dvr" /> 
 <Supplier Id="klr" /> 
 </Suppliers>
 </data>

 <data>
  <service provider>svr</service provider> 
  <Customer>raj</Customer> 
  <Suppliers>
    <Supplier Id="avr" /> 
    <Supplier Id="csr" /> 
    <Supplier Id="ksr" /> 
  </Suppliers>
</data>

<data>
  <service provider>avr</service provider> 
  <Customer>svr</Customer> 
  <Suppliers>
    <Supplier Id="Bpv" /> 
    <Supplier Id="Wrr" /> 
    <Supplier Id="Sdr" /> 
  </Suppliers>
</data>

<data>
  <service provider>csr</service provider> 
  <Customer>svr</Customer> 
  <Suppliers>
   <Supplier Id="bvs"  /> 
   <Supplier Id="vvs" /> 
   <Supplier Id="Ssv" /> 
  </Suppliers>
 </data>

 <data>
   <service provider>klr</service provider> 
   <Customer>PUMC</Customer> 
   <Suppliers>
     <Supplier Id="ssn" /> 
     <Supplier Id="qis" /> 
     <Supplier Id="nan" /> 
    </Suppliers>
 </data>
</orderinfo>
in the above xml file represents customer and service information.
first I need to represent customer as node and service provider is another node and suppliers id are nodes and I need to edge all of them in the manner as shown below.for example first node in my xml data
Code:
 
                                            bvr(customer)
                                   
                                            raj(service provider)

                       svr(supplier)     dvr(supplier)         klr(supplier)
I need to connect edges from three supliers to raj and from raj to bvr. then coming to the next node in my xml data customer is "raj" so we have already node for "raj" then see service provider is "svr" so we have node for "svr" also then see service supplier we dont have nodes so create nodes and link between "svr" and his service suppliers. like that i need to do iterations and write graphML file for this xml file.
graphMl like this
Code:
<graph id="G" edgedefault="directed">
    <node id="bvr">
     </node>
    <node id="raj">
    </node>
     <node id="svr">
    </node>
      <node id="dvr">
    </node>
       <node id="klr">
         </node>
    <edge source="raj" target="bvr">
    </edge>
<edge source="svr" target="raj">
    </edge>
<edge source="dvr" target="raj">
    </edge>
<edge source="klr" target="raj">
    </edge>
  </graph>
help me with this problem.

Thanks in advance.
 
Old November 23rd, 2011, 02:20 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think this actually boils down to a grouping problem. You have a group of several customer elements in the input that result in a single node element in the output graph. Assuming you are using XSLT 2.0, you will want to do something like

Code:
<xsl:for-each select="distinct-values(//customer)">
  <g:node id="{.}"/>
</xsl:for-each>
The same might also be true for service providers and suppliers, it's not clear whether these can be duplicated in your input.

Hopefully the problem should then be easier. Note that with this kind of problem, it's usually easier to make the logic output-driven rather than input-driven. Don't ask "I've found X in the input, what should I do with it?", rather ask "I need to generate X in the output, what information do I need to compute it?". That's the essence of a functional programming approach.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 24th, 2011, 12:26 PM
Authorized User
 
Join Date: Nov 2011
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply may be I will try like that. still its little bit complicated for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF to XML conversion bcogney XSLT 7 September 21st, 2011 06:27 AM
XLST noob - XML -> XML transform help required Crass1968 XSLT 6 March 4th, 2010 07:32 AM
.csv to xml conversion balakrishna XML 0 March 5th, 2007 01:07 PM
Very confused on XML to XML conversion mal141 XSLT 2 August 11th, 2006 02:44 AM
xml to graphml rimisark XSLT 4 August 8th, 2006 09:43 PM





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