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 June 17th, 2005, 01:34 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml to graphml

hi there,
i am a beginner in XSLT. i tried for two days to convert a graph made in visio to graphml. i managed with the nodes, but have problems with the links can anyone help please. here are the source and the target XML

<?xml version='1.0' encoding='utf-8' ?>
<Connects>
<Connect FromSheet='4' FromCell='BeginX' FromPart='9' ToSheet='1' ToCell='Connections.X2' ToPart='101'/>
<Connect FromSheet='4' FromCell='EndX' FromPart='12' ToSheet='2' ToCell='Connections.X4' ToPart='103'/>
<Connect FromSheet='5' FromCell='BeginX' FromPart='9' ToSheet='1' ToCell='Connections.X1' ToPart='100'/>
<Connect FromSheet='5' FromCell='EndX' FromPart='12' ToSheet='3' ToCell='Connections.X3' ToPart='102'/>
<Connect FromSheet='7' FromCell='BeginX' FromPart='9' ToSheet='6' ToCell='Connections.X4' ToPart='103'/>
<Connect FromSheet='7' FromCell='EndX' FromPart='12' ToSheet='3' ToCell='Connections.X2' ToPart='101'/>
</Connects>


<?xml version="1.0" encoding="UTF-8"?>
  <graph>
    <edge id="4" source="1" target="2"/>
    <edge id="5" source="1" target="3"/>
    <edge id="7" source="6" target="9"/>
  </graph>


thanks in advance.

krasimir

 
Old June 17th, 2005, 07:07 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its me again.
I tried something like... for each Connects/Connect I do If [@FromCell='BeginX'] to capture the source id. then i tried to open element "edge" and to add the source id attribute. Also i did If [@FromCell='EndX'] to capture the target id. My idea was to add the target attribute and close the element "edge" in the second if, but was unable to compile this solution. can anyone help please...

krasimir

 
Old June 17th, 2005, 08:35 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Hi !

Got your solution:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates select="Connects"/>
    </xsl:template>
    <xsl:template match="Connects">
        <graph>
            <xsl:apply-templates select="Connect[@FromCell = 'BeginX']"/>
        </graph>
    </xsl:template>
    <xsl:template match="Connect">
        <xsl:element name="edge">
            <xsl:attribute name="id">
                <xsl:value-of select="@FromSheet"/>
            </xsl:attribute>
            <xsl:attribute name="source">
                <xsl:value-of select="@ToSheet"/>
            </xsl:attribute>
            <xsl:attribute name="target">
                <xsl:value-of select="following-sibling::Connect[@FromCell = 'EndX' and @FromSheet = ./@FromSheet]/@ToSheet"/>
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Keep reading the forum, you'll learn fast over time.

Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old June 17th, 2005, 08:42 AM
Registered User
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks alot, rushman! I knew you can do it. Just saw one of your other replies and knew you have the skills! Hope i will be able to do tasks like this myself soon. Thanks again!!!

 
Old August 8th, 2006, 09:43 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pkhoosh Send a message via Yahoo to pkhoosh
Default

How do I apply the style sheet?

Quote:
quote:Originally posted by rushman
 Hi !

Got your solution:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates select="Connects"/>
    </xsl:template>
    <xsl:template match="Connects">
        <graph>
            <xsl:apply-templates select="Connect[@FromCell = 'BeginX']"/>
        </graph>
    </xsl:template>
    <xsl:template match="Connect">
        <xsl:element name="edge">
            <xsl:attribute name="id">
                <xsl:value-of select="@FromSheet"/>
            </xsl:attribute>
            <xsl:attribute name="source">
                <xsl:value-of select="@ToSheet"/>
            </xsl:attribute>
            <xsl:attribute name="target">
                <xsl:value-of select="following-sibling::Connect[@FromCell = 'EndX' and @FromSheet = ./@FromSheet]/@ToSheet"/>
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Keep reading the forum, you'll learn fast over time.

Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
Creating XML doc ; writing string(xml format) into KamalRaturi XML 5 May 28th, 2008 05:51 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM





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