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 5th, 2006, 03:07 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deal with multiple sources

Hi,

I have 2 source files .xmi and .graphml I merge both by writing the second file before the root end tag of the first then I wrote my xslt, I've got a correct output but this was not the right way to deal with multiple sources. How can I convert the following xslt to deal with 2 files rather than a merged file.

Code:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:UML="org.omg.xmi.namespace.UML" xmlns:a="http://graphml.graphdrawing.org/xmlns/graphml">
    <xsl:output method="xml"/>
    <xsl:template match="/">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>    
    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="UML:Namespace.ownedElement[local-name(parent::*[1]) = 'Model']">
            <xsl:copy>
                <xsl:call-template name="graphml"/>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates/>
            </xsl:copy>            
    </xsl:template>

    <xsl:template name="graphml">
        <xsl:for-each select="//a:graphml/.//a:cluster">
            <xsl:choose>
                <xsl:when test="count(child::*) &gt; 1">
                <xsl:variable name="cOne" select="child::*[1]/@name"/>
                <xsl:variable name="cTwo" select="child::*[2]/@name"/>
                <xsl:if test="not((count(child::*) = '2') and ((contains($cOne, '.java') and contains($cOne, $cTwo)) or (contains($cTwo, '.java') and contains($cTwo, $cOne))))">
                    <xsl:element name="UML:Component">
                        <xsl:attribute name="xmi.id">
                            <xsl:text>.:000</xsl:text>
                            <xsl:value-of select="@id"/>
                        </xsl:attribute>
                        <xsl:attribute name="isSpecification">false</xsl:attribute>
                        <xsl:attribute name="isRoot">false</xsl:attribute>
                        <xsl:attribute name="isLeaf">false</xsl:attribute>
                        <xsl:attribute name="isAbstract">false</xsl:attribute>
                        <xsl:copy-of select="@name"/>
                        <xsl:element name="UML:ModelElement.clientDependency">
                            <xsl:for-each select="a:node">
                                <xsl:element name="UML:Dependency">
                                    <xsl:attribute name="xmi.idref">
                                        <xsl:value-of select="@xmi.id"/>
                                    </xsl:attribute>
                                    <xsl:apply-templates/>
                                </xsl:element>
                            </xsl:for-each>
                        </xsl:element>
                    </xsl:element>
                </xsl:if>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="*[*/UML:Package/@xmi.idref]"/>

    <xsl:template match="UML:Package[not(@xmi.idref)]">
        <xsl:apply-templates select="UML:Namespace.ownedElement/child::node()"/>
    </xsl:template>

    <xsl:template match="a:graphml"/>
</xsl:stylesheet>
Thanks,
Hind

 
Old June 5th, 2006, 03:34 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't follow all your code without knowing more about your problem, but my guess would be that in teh template name="graphml" you can simply replace

<xsl:for-each select="//a:graphml/.//a:cluster">

by something like

<xsl:for-each select="document('graphml.xml')//a:graphml/.//a:cluster">

There are lots of oddities in your code. For example the above path expression is equivalent to "//a:graphml//a:cluster"

I personally find this kind of code really verbose:

<xsl:element name="UML:Dependency">
                                    <xsl:attribute name="xmi.idref">
                                        <xsl:value-of select="@xmi.id"/>
                                    </xsl:attribute>
                                    <xsl:apply-templates/>
                                </xsl:element>

Much better to write

  <UML:Dependency xml.idref="{@xmi.id}">
    <xsl:apply-templates/>
  </UML:Dependency>

This match pattern:

match="UML:Namespace.ownedElement[local-name(parent::*[1]) = 'Model']

seems to be a particularly obscure way of writing:

match="*:Model/UML:Namespace.ownedElement"

(Do you really not know the namespace of the parent element?)


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 5th, 2006, 07:16 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for bad code, but this is because its my first xsl code.

The problem is that I want to generate component elements as a child of the first "UML:Namespace.ownedElement" element wich is chield of "UML:Model".
"UML:Model" has exactly 2 children "UML:ModelElement.TaggedVlaue" and "UML:Namespace.ownedElement" which may contain some descendants with the same name.

I will generate a component based on .graphML file as follow:

for each cluster that contains more than one child
if cluster contains 2 children and the name of ane of them = the name of the other=".jave"
then do nothing
else create a component.

Following is the graphml part of the source file:
Code:
<graphml xmlns="http://graphml.graphdrawing.org/xmlns/graphml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/graphml">
        <graph edgedefault="directed" Edge_Weight_Key="edu.uci.ics.jung.graph.decorators.EdgeWeightLabeller@19e15c"
            Clustering_Weight_Key="edu.uci.ics.jung.graph.decorators.EdgeWeightLabeller@11a75a2"
            StringLabeller.LabelDefaultKey="edu.uci.ics.jung.graph.decorators.StringLabeller@210b5b">
            <clusters>
                <cluster id="1">
                    <node id="17" xmi.id=".:00000000000007D6" name="AstroRecord.java" />
                    <node id="6" xmi.id=".:00000000000007D7" name="AstroRecord" />
                    <node id="27" xmi.id=".:0000000000000875" name="DataInput" />
                </cluster>
                <cluster id="2">
                    <node id="25" xmi.id=".:0000000000000805" name="WritePDB" />
                    <node id="21" xmi.id=".:0000000000000804" name="WritePDB.java" />
                </cluster>
                <cluster id="3">
                    <node id="12" xmi.id=".:00000000000007F8" name="CatalogRecord" />
                </cluster>
                <cluster id="4">
                    <node id="4" xmi.id=".:0000000000000B90" name="Vector" />
                </cluster>
                <cluster id="5">
                    <node id="24" xmi.id=".:00000000000007E0" name="ConvertDST" />
                    <node id="15" xmi.id=".:00000000000007DF" name="ConvertDST.java" />
                </cluster>
                <cluster id="6">
                    <node id="24" xmi.id=".:00000000000007E0" name="ConvertDST" />
                    <node id="15" xmi.id=".:00000000000007DF" name="ConvertDST.java" />
                </cluster>
                <cluster id="7">
                    <node id="1" xmi.id=".:000000000000086D" name="DataOutput" />
                    <node id="23" xmi.id=".:0000000000000829" name="RecordIndex.java" />
                    <node id="9" xmi.id=".:0000000000000820" name="PDBElement.java" />
                    <node id="3" xmi.id=".:0000000000000A68" name="Date" />
                    <node id="10" xmi.id=".:000000000000083B" name="RecordOffset.java" />
                    <node id="12" xmi.id=".:00000000000007F8" name="CatalogRecord" />
                    <node id="18" xmi.id=".:0000000000000821" name="PDBElement" />
                    <node id="13" xmi.id=".:0000000000000814" name="DatabaseHeader" />
                    <node id="5" xmi.id=".:000000000000082A" name="RecordIndex" />
                    <node id="19" xmi.id=".:000000000000083C" name="RecordOffset" />
                    <node id="20" xmi.id=".:000000000000080D" name="DatabaseHeader.java" />
                    <node id="26" xmi.id=".:000000000000085D" name="String" />
                </cluster>
                <cluster id="8">
                    <node id="25" xmi.id=".:0000000000000805" name="WritePDB" />
                    <node id="21" xmi.id=".:0000000000000804" name="WritePDB.java" />
                </cluster>
                <cluster id="9">
                    <node id="22" xmi.id=".:00000000000007E3" name="DSTRecord" />
                </cluster>
                <cluster id="10">
                    <node id="8" xmi.id=".:00000000000007CE" name="AstroAppInfo" />
                    <node id="14" xmi.id=".:00000000000007CD" name="AstroAppInfo.java" />
                </cluster>
                <cluster id="11">
                    <node id="2" xmi.id=".:00000000000007EE" name="DumpPDB.java" />
                    <node id="11" xmi.id=".:00000000000007EF" name="DumpPDB" />
                </cluster>
                <cluster id="12">
                    <node id="22" xmi.id=".:00000000000007E3" name="DSTRecord" />
                </cluster>
                <cluster id="13">
                    <node id="10" xmi.id=".:000000000000083B" name="RecordOffset.java" />
                    <node id="19" xmi.id=".:000000000000083C" name="RecordOffset" />
                </cluster>
                <cluster id="14">
                    <node id="16" xmi.id=".:00000000000007FC" name="ParseCatalog" />
                    <node id="7" xmi.id=".:00000000000007F7" name="ParseCatalog.java" />
                </cluster>
            </clusters>
            <edges>
                <edge source="5" target="27" directed="true" RelType="Coupling" edge_weight="28.0" isRemoved="True" />
                ....
            </edges>
        </graph>
    </graphml>
</XMI>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Datasets from multiple Data Sources SQL_Hacker Reporting Services 1 June 18th, 2008 02:25 PM
Populating DropDownList from multiple sources hawkfb63 ASP.NET 2.0 Professional 2 February 14th, 2006 06:42 PM
Query from multiple data sources billmedd BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 September 27th, 2004 10:46 AM
one record set multiple data sources jack1234 Classic ASP Professional 1 October 17th, 2003 12:50 PM





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