aspose file tools*
The moose likes XML and Related Technologies and the fly likes override xml/xsd file by using .xsl and java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "override xml/xsd file by using .xsl and java" Watch "override xml/xsd file by using .xsl and java" New topic
Author

override xml/xsd file by using .xsl and java

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
hi ,

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

thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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

Joined: May 20, 2008
Posts: 180
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
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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

Joined: May 20, 2008
Posts: 180
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
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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

Joined: May 20, 2008
Posts: 180
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
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sounds like a job more suited for a short, efficient Perl program rather than a complex, ugly XSL file.
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
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
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: override xml/xsd file by using .xsl and java
 
Similar Threads
displaying image in any browser using xsl
how to generate xml file using xsd schema in java ?
Genrating xml from the given xsd
converting xsd to html
help - Question on XSD and XSL