• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

override xml/xsd file by using .xsl and java

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

i want to override xml/xsd file by using xsl and java, it there anyone can provide me a reference?

thank you
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you explain your requirement a bit more? For example what do you mean when you say you want to "override" those files?
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Could you explain your requirement a bit more? For example what do you mean when you say you want to "override" those files?



for ie, i have the following .xsd file:
<xs:schema xmlns:tns="AA" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="BB" version="1.0">
<xs:complexType name="codedValue">
<xs:sequence>
<xs:element name="codeSystem" type="xs:string"/>
<xs:element name="code" type="xs:string"/>
<xs:element name="displayName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

i want it to be converted to :

<xs:schema xmlns:tns="AA" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="BB" version="1.0">
<xs:complexType name="codedValue">
<xs:sequence>
<xs:element name="codeSystem" type="tns:CAHR_10"/>
<xs:element name="code" type="tns:CAHR_12"/>
<xs:element name="displayName" type="tns:CAHR_15" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


HOW can i do it?

thank you
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, you could certainly write an XSL transformation to transform the first schema to the second. But on the other hand you could spend a couple of minutes with a text editor to do the same thing. When you say you need an automated transformation it makes me suspect that you are just providing a random example of your actual, unstated, requirement.
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Okay, you could certainly write an XSL transformation to transform the first schema to the second. But on the other hand you could spend a couple of minutes with a text editor to do the same thing. When you say you need an automated transformation it makes me suspect that you are just providing a random example of your actual, unstated, requirement.



the problem is that the schema is huge, that is why i need to auto the transformation, instead of editing in text pad .....

can you provide me a sample code? or reference?
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you haven't provided any requirements for this transformation, so naturally it wouldn't be possible to post any sample code. All we can tell is that you want to change type="xs:string" to type="something else" for no apparent reason.

However in general when you want to transform a document into a document of the same form with minor changes, the strategy to use is to start with the identity transformation and add templates to do the specific changes you want. So start there. Let us know how it goes.
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Well, you haven't provided any requirements for this transformation, so naturally it wouldn't be possible to post any sample code. All we can tell is that you want to change type="xs:string" to type="something else" for no apparent reason.

However in general when you want to transform a document into a document of the same form with minor changes, the strategy to use is to start with the identity transformation and add templates to do the specific changes you want. So start there. Let us know how it goes.



well my requirement here is very clear that i need transfter type="xs:string" -> type="tns:CAHR_12", this is all i wanted.
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jim li wrote:well my requirement here is very clear that i need transfter type="xs:string" -> type="tns:CAHR_12", this is all i wanted.



But you also posted

as part of your desired output. Was that a misprint, then?
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job more suited for a short, efficient Perl program rather than a complex, ugly XSL file.
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wrote a simple xsl script:



for xml file:


i output the value:


which is exactly i wanted, however, when i changed the script to:


the output is :

but i expected the output to be:


can anyone give me some suggestion?
 
Paul Clapham
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your XML; I think you'll agree they make your post much more readable.

As for your second transformation: the transformation starts by considering the root element. It does indeed find a template which can process that root element. That template asks whether the current node is a Customer element. Since it is not -- it is a Root element -- the template does nothing. In particular, it doesn't call <xsl:apply-templates> so no other nodes are processed. And that's all it does: nothing.

I hope that's what you meant when you asked for a "suggestion".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!