Jump to content

using xslt to generate more meaningful xml-schema


Britz

This topic is 7666 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

I have the following specific problem..

I have xml-files which have the following general format:

...

...

...

<object id="11534" type="6">

<property id="393228">

<int>33554431</int>

</property>

</object>

...

...

...

where a property can (instead of type int) be a object again, or a objref, or a simple type.

I want to use xslt to transform this format, to something more specific like:

<object6 id="11534">

<property id="393228">

<int>33554431</int>

</property>

</object6>

(So object types can be distinguished by looking only at the name of the tag.)

Can anyone tell me how to do the above transform?

Thanks in advance,

Britz

..........................................................................

The background info....

I use a program (J.D Edwards Solution Modeler) to generate processmodels. This program exports to xml. The goal is to create a conversion tool that converts any xml-file created with this program to the PNML-standard. (Petri-net standard of xml)

I have the xml-schema of the pnml-standard, but the problem is that i haven't got the XML-schema of the source file. Furthermore, the people of J.D Edwards didn't make it easy to do by hand, as the xml-file is terrible to read for the (not so trained) human eye.

I use XMl-spy to generate a XMl-schema from the xml-file , but the schema is far to generic to be of any use. Therefore i want to transform the xml-file, in such a way that xml-spy generates a more specific xml-schema. Then i can go and make a xslt-schema to transform one xml-schema to the other.

Link to comment
Share on other sites

Probably not the right list for such a specific non-FileMaker XSLT question, but here is a working code snippet:

<xsl:for-each select="object">

<xsl:variable name="temp">

<xsl:value-of select="name()"/>

<xsl:value-of select="@type"/>

</xsl:variable>

<xsl:element name="{$temp}"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute><xsl:value-of select="*"/></xsl:element>

</xsl:for-each>

Link to comment
Share on other sites

  • Newbies

Thanks for your reply.

I'm an newbie to XSL(T) so bplease bare with me..

I used your code-snippet to make the following xslt-file but it gave an error, van you tell me what's wrong?

-----

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:for-each select="object">

<xsl:variable name="temp">

<xsl:value-of select="name()"/>

<xsl:value-of select="@type"/>

</xsl:variable>

<xsl:element name="{$temp}"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute><xsl:value-of select="*"/></xsl:element>

</xsl:for-each>

</xsl:stylesheet>

Thanks in advane,

Geert-Jan Brits

The Netherlands

Link to comment
Share on other sites

>I use XMl-spy to generate a XMl-schema from the xml-file , but the schema is far to generic to be of any use. Therefore i want to transform the xml-file, in such a way that xml-spy generates a more specific xml-schema. Then i can go and make a xslt-schema to transform one xml-schema to the other.

the <xsl:template> tags ar missing, the correct XPATH for the object (its position in the XML tree) will have to be added.

XML Spy should give you the basic "strawman" you need for XML-XML conversion. Simply replace the references to /.?./.?./?./object*

with the code snippet.

Reverse-engineering a Schema is not really a project for someone completely new to XML and XSLT, though. Took me weeks to get into this.

Link to comment
Share on other sites

This topic is 7666 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.