0

Hey guys,

I'm tying to merge two XML file for days but it doesn't work. Here is the problem:

I want to merge these XML files:
graphs.xml

<?xml version='1.0' encoding='utf-8'?>
<ph:Graphs xmlns:ph="http://www.merge.something.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <ph:Graph name="mass_spring_mo">
        <ph:Element id="0" type="Mass">
            <ph:Attribute>
                <ph:AttributeField name="type" value="float" />
            </ph:Attribute>
            <ph:Port id="1" type="port">
                <ph:Attribute>
                    <ph:AttributeField name="type" value="int" />
                </ph:Attribute>
            </ph:Port>
        </ph:Element>
        <ph:Edge id="3" sourceid="4" targetid="5" />
    </ph:Graph>
</ph:Graphs>

and metamodel.xml

<?xml version='1.0' encoding='utf-8'?>
<ph:Metamodel xmlns:ph="http://www.merge.something.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ph:ElementType name="ElementType">
        <ph:ElementType name="Mass">
            <ph:Attribute>
                <ph:AttributeField name="type" value="int" />
                <ph:AttributeField name="name" value="m" />
                <ph:AttributeField name="value" value="5" />
                <ph:AttributeField name="send_to_graph_rewrite_engine" value="True" />
            </ph:Attribute>
        </ph:ElementType>
    </ph:ElementType>
</ph:Metamodel>

Therefore I created an index.xml file:

<?xml version="1.0"?>
<ph:index xmlns:ph="http://www.merge.something.com">
   <ph:entry>graphs</ph:entry>
   <ph:entry>metamodel</ph:entry>
</ph:index>

An I started with this XSLT file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xxmlns:ph="http://www.merge.something.com">

<xsl:output method="xml"/>

<xsl:template match="booggie:index">
      <xsl:apply-templates/>
</xsl:template>


<xsl:template match="ph:index/ph:entry">
   <xsl:apply-templates select="document(concat(.,'.xml'))"/>
</xsl:template>

<xsl:template match="ph:Graphs">
   <xsl:value-of select="ph:Graph"/>
</xsl:template>


</xsl:stylesheet>

My disered output should be looking like that:

<?xml version='1.0' encoding='utf-8'?>
<ph:Graphs xmlns:ph="http://www.merge.something.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <ph:Graph name="mass_spring_mo">
        <ph:Element id="0" type="Mass">
            <ph:Attribute>
                <ph:AttributeField name="type" value="float" />
            </ph:Attribute>
            <ph:Attribute>
                <ph:AttributeField name="type" value="int" />
                <ph:AttributeField name="name" value="m" />
                <ph:AttributeField name="value" value="5" />
                <ph:AttributeField name="send_to_graph_rewrite_engine" value="True" />
            </ph:Attribute>
            <ph:Port id="1" type="port">
                <ph:Attribute>
                    <ph:AttributeField name="type" value="int" />
                </ph:Attribute>
            </ph:Port>
        </ph:Element>
        <ph:Edge id="3" sourceid="4" targetid="5" />
    </ph:Graph>
</ph:Graphs>

But there is no output!? Where is error!? Can anyone help me please.
Thanks!

Bye Michael

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by xml_looser
0

this will work in browser only opera 11
when you use xslt2 parser this will work too
xml graphs.xml

<?xml-stylesheet href="graphs.xsl" type="text/xsl" ?>
<ph:Graphs xmlns:ph="http://www.merge.something.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<ph:Graph name="mass_spring_mo">
		<ph:Element id="0" type="Mass">
			<ph:Attribute>
				<ph:AttributeField name="type" value="float"/>
			</ph:Attribute>
			<ph:Port id="1" type="port">
				<ph:Attribute>
					<ph:AttributeField name="type" value="int"/>
				</ph:Attribute>
			</ph:Port>
		</ph:Element>
		<ph:Edge id="3" sourceid="4" targetid="5"/>
	</ph:Graph>
</ph:Graphs>

xml metamodel.xml

<ph:Metamodel xmlns:ph="http://www.merge.something.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<ph:ElementType name="ElementType">
		<ph:ElementType name="Mass">
			<ph:Attribute>
				<ph:AttributeField name="type" value="int"/>
				<ph:AttributeField name="name" value="m"/>
				<ph:AttributeField name="value" value="5"/>
				<ph:AttributeField name="send_to_graph_rewrite_engine" value="True"/>
			</ph:Attribute>
		</ph:ElementType>
	</ph:ElementType>
</ph:Metamodel>

xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ph="http://www.merge.something.com">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<ph:Graphs>
			<xsl:apply-templates select="ph:Graphs"/>
		</ph:Graphs>
	</xsl:template>
	<xsl:template match="ph:Graphs">
		<xsl:apply-templates select="ph:Graph"/>
	</xsl:template>
	<xsl:template match="ph:Graph">
		<ph:Graph name="{@name}">
			<xsl:apply-templates select="ph:Element"/>
		</ph:Graph>
	</xsl:template>
	<xsl:template match="ph:Element">
		<xsl:variable name="type" select="@type"/>
		<ph:Element id="{@id}" type="{@type}">
			<xsl:apply-templates select="ph:Attribute"/>
			<xsl:variable name="metamodel">
				<xsl:copy-of select="document('metamodel.xml')//ph:ElementType[@name=$type]/ph:Attribute"/>
			</xsl:variable>
			<xsl:copy-of select="$metamodel"/>
			<xsl:apply-templates select="ph:Port"/>
		</ph:Element>
	</xsl:template>
	<xsl:template match="ph:Attribute">
		<xsl:copy-of select="."/>
	</xsl:template>
	<xsl:template match="ph:Port">
		<xsl:copy-of select="."/>
	</xsl:template>
</xsl:stylesheet>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.