简体   繁体   中英

convert/transform XML to XSL

/ Hell0 guys, I will try to be as specific as possible, because I came here after some time googling and you-tubing about transforming XML to XSL.. but I could not find or understand. Deal is, I got task ( btw. NEVER even touched XML or XSL ) to create a model of lets say Customer and Carrier. First step is when Customer sends an order to Carrier ( may sound stupid :) ). So using eClipse I've created

orderForCarrier.xsd , then using website : https://devutilsonline.com/xsd-xml/generate-xml-from-xsd I've created XML file.

So now, the final task is (problem is, I am not VERY sure what I need to do) to make transformation to XSL file.

example of XML file I got generated :

<?xml version="1.0"?>

<cus:sendOrderToCarrier xmlns:cus="http://www.example.org/Customer">

<cus:customerCompanyName>

<cus:companyName>string</cus:companyName>

<cus:Name>string</cus:Name>

<cus:SurrName>string</cus:SurrName>

<cus:SSN>3</cus:SSN>

</cus:customerCompanyName>

<cus:orderDetails>string</cus:orderDetails>

</cus:sendOrderToCarrier>

As much I understand, deal is to make XSL file,so when Customer sends order to Carrier, it will get formatted in the way Carrier needs it and vise-versa.

For conclusion, it's not a homework or something like that, I am very new Java developer, but I got this monkey tasks and I am kinda stuck here, because I even dont know what I am dealing with.

So ANY help would be really great.

thanks in advance.

Though I think the comments already cover your question, let me give it a go regardless:

about transforming XML to XSL..

XSLT is a language, XML is (usually) the source. The language XSLT is written in XML. What you are asking here is like saying "how to transform a text file into C#".

My guess is: you have some kind of target format in XML and some kind of source format (maybe XML, maybe text), and you would like XSLT to transform it from source to target.

So now, the final task is (problem is, I am not VERY sure what I need to do) to make transformation to XSL file.

This is problematic: if you don't know what your task is, then it will be very hard to help you, because we really need you to explain what you want.

So using eClipse I've created orderForCarrier.xsd

Why? What is the task here? Was this also auto-generated?

then using website : https://devutilsonline.com/xsd-xml/generate-xml-from-xsd I've created XML file.

That creates random input. It will be very hard to do anything meaningful with it. Fill it with data you actually have, or something very close to it.

As much I understand, deal is to make XSL file,so when Customer sends order to Carrier, it will get formatted in the way Carrier needs it and vise-versa.

So, the customer knows XML and will use XSLT? I assume that the expects some kind of format, but without knowing what that format is, we can't help you.

Some suggestions:

  • Make sure you fully understand the task, it makes no sense to build a bridge if the customer expects a painting
  • Typical scenarios with XSLT include situations where you need to exchange data. The format used internally is not the same as the receiver uses internally. If both can exchange in XML, you can agree on a format in XML and transform your data (using XSLT or otherwise) to that format. I'm not even sure you need it in your scenario.
  • Before you do anything with XSLT, or even XML or XSD, make sure you understand the basics. Do not auto-generate stuff! Auto-generation is only meaningful if you understand the basics and beyond, otherwise it will only cloud your understanding. If your requirements mandate using the trio XML, XSD, XSLT, then proceed as follows (and take your time):
    • Read about XML
    • Read about basics of XSD, create a very simple example by hand that takes a few fields, string, number, and move on from there.
    • Understand the meaning of well-formed and valid XML. Create examples (by hand!) that fail, see what happens, and examples that succeed.
    • Start with the basics of XSLT, create a single transformation with a single matching template. Run it (all by hand, no auto-generation). Add more templates, and try to understand each step.
    • If you got this far you are ready to ask meaningful questions for things you can't figure out, you can then show us what you are doing and where you are stuck

Happy coding! For each step above there are many paid and unpaid tutorials online. But like any other language out there, it takes time to master it, so give yourself that time, stay away from auto-generation, and do it step by step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM