XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
alejandro salasSubject: Identity Transform problem. Hibernate Mapping
Author: alejandro salas
Date: 23 Jun 2006 05:34 PM
Hi everyone,
I'm new to xslt so this may be a very dumb question. I'm trying to transform an Hibernate Mapping (template) file, into a complete mapping file.

My template:
----------------------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="" table="" lazy="false">

<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>

<property name=""/>
</class>
</hibernate-mapping>
----------------------------

I want to fill the name and table attributes in the class element, and the name attribute in the property element. (All values should come from another xml.)

My first attempt was to transform it including dummy values so that I could figure out later how to import the values from a different xml file. My xslt copies everything but the class element and the property element, I've had problems figuring out the rest.
Here's my xslt:
------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="class">
<xsl:copy-of select="id"/>
</xsl:template>
</xsl:stylesheet>
--------------------------

Any help is appreciated.
Thanx in advance.

Postnext
alejandro salasSubject: Identity Transform problem. Hibernate Mapping
Author: alejandro salas
Date: 23 Jun 2006 05:47 PM
I actually managed to change add a couple of things, my output xml is fine now, but I need to know how could I import the values I want from another xml (all the attributes must be added from that other source). And another thing is that I'm pretty sure there's a better way to do it, so, any help is greatelly appreciated. Here's my xslt:
---------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="class">
<xsl:copy>
<xsl:attribute name="name">myModel</xsl:attribute>
<xsl:attribute name="table">myTable</xsl:attribute>
<xsl:attribute name="lazy">false</xsl:attribute>
<xsl:text>
<xsl:copy-of select="id"/>
</xsl:text>
<xsl:text>
<xsl:element name="property">
<xsl:attribute name="name">myVal</xsl:attribute>
</xsl:element>
</xsl:text>
<xsl:text>
</xsl:text>
</xsl:copy>
</xsl:template>
---------------------------

Postnext
Ivan PedruzziSubject: Identity Transform problem. Hibernate Mapping
Author: Ivan Pedruzzi
Date: 23 Jun 2006 07:16 PM
Hi Alejandro,

If you post a sample of the input documents you would like to use and the desired output we will show you a full solution.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
alejandro salasSubject: Identity Transform problem. Hibernate Mapping
Author: alejandro salas
Date: 27 Jun 2006 06:34 PM
Xml template file:
---------------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class lazy="false">

<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>
---------------------

Xml input:
---------------------
<?xml version="1.0"?>
<model name="someName" table="someTable">
<property name="someProp"/>
</model>
---------------------

Xml output:
---------------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="someName" table="someTable" lazy="false">

<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>

<property name="someProp"/>
</class>
</hibernate-mapping>
---------------------

One of the problems I encountered is that the elements in my output xml appeared with a lot of other attributes (the ones defined in the dtd).
Example:
<property name="someProp" unique="false" optimistic-lock="true" lazy="false" generated="never" /> instead of just
<property name="someProp"/>

As I said before I couldn't figure out how to transform my xml template using another file as input. I solved it using DOM, but I'd like to use transformations instead.

Thanx for all the help
Alejandro

Posttop
Ivan PedruzziSubject: Identity Transform problem. Hibernate Mapping
Author: Ivan Pedruzzi
Date: 28 Jun 2006 01:15 AM
Originally Posted: 28 Jun 2006 01:12 AM
I am not sure how your template works.

Please see the attached solution that demonstrates the following

- generating a reference to a DTD in the output document using xsl:output

- implementing an identity transformation that copies everything in input to the output

- use the document function to access a document other then the default input document

The attributes you see appearing in the output come from the DTD schema either when there is reference in the XML input document or when the XSLT output generates the doctype

Hope this helps
Ivan Pedruzzi
Stylus Studio Team


Documenthibernate.xml


Documenthibernate(1).xml


Documenthibernate_secondary_input.xml


Documenthibernate.xsl

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.