How to create XSLT for my XML doc?
Hi,
I am a new comer to XSLT. I have a XML schema which look like this
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="www.myCompany.com/XMLSchema" xmlns:f="www.mycompany.com/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="xRecord">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="CommentText" type="xs:string" minOccurs="0"/>
<xs:element name="OrganizationID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="xFunctionRecord">
<xs:complexType>
<xs:sequence>
<xs:element name="functionCommentText" type="xs:string" minOccurs="0"/>
<xs:element name="OrganizationID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I need create a XSLT again this schema. Can anyone show me how to do that?
Thank you very much.
Re: How to create XSLT for my XML doc?
Do you have a schema for your result xml?
only thing you can make out from this so far is a few templates,
<xsl:template match="xRecord">
<xsl:template match="CommentText">
etc...
Re: How to create XSLT for my XML doc?
This is a schema for my result xml. If you think it is not correct, can you show me where I need correct it? And also, the xslt need tranform xml file into a string object. I tried to figure out how to do that.
Thanks
Re: How to create XSLT for my XML doc?
is Source -> Result
XML -> String?
You need to be more specific in what you want to output. For example,
<xsl:template match="\*">a</xsl:template>
is an xslt file which will take any xml file and output the string "a". This probably isn't what you want.
What does your input look like; what does your output look like?
Re: How to create XSLT for my XML doc?
I am facing the same problem.
Plz let me know if u can find the solution.
Re: How to create XSLT for my XML doc?
There is no 'the solution'
As jkmyoung hints. There is an infinete number of possible solutions. But you have to put in at least some work to get one that is usfull to you.
If you want to learn how to write XSL code, go search google for xsl tutorials.
Re: How to create XSLT for my XML doc?
Quote:
Originally Posted by beachboy1976
Hi,
I am a new comer to XSLT. I have a XML schema which look like this
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="www.myCompany.com/XMLSchema" xmlns:f="www.mycompany.com/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="xRecord">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="CommentText" type="xs:string" minOccurs="0"/>
<xs:element name="OrganizationID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="xFunctionRecord">
<xs:complexType>
<xs:sequence>
<xs:element name="functionCommentText" type="xs:string" minOccurs="0"/>
<xs:element name="OrganizationID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I need create a XSLT again this schema. Can anyone show me how to do that?
Thank you very much.
you sound like a beginner - it's not clear what you mean by writing an XSLT against this schema. What do you want the XSLT to do with the schema? Usually XSLT is used against XML instance documents (i.e. instances of XML data, not the XML data model itself). Anyway... one way to help is to use a tool, for example, an XML Schema Editor and an xslt editor could help you write the code for whatever it is you're trying to do.
Sincerely,
The Stylus Studio team
http://www.stylusstudio.com
Re: How to create XSLT for my XML doc?
Quote:
Originally Posted by stylusstudio
you sound like a beginner - it's not clear what you mean by writing an XSLT against this schema. What do you want the XSLT to do with the schema? Usually XSLT is used against XML instance documents (i.e. instances of XML data, not the XML data model itself). Anyway... one way to help is to use a tool, for example, an
XML Schema Editor and an
xslt editor could help you write the code for whatever it is you're trying to do.
Sincerely,
The Stylus Studio team
http://www.stylusstudio.com
Tut-tut - the Stylus Studio Team sound a bit like beginners themselves. What BeachBoy1976 appeared to be after was advice on how to write an XSLT that will transform the XML Schema into an XSLT that he can then apply to instances of XML documents. That is a perfectly logical (and advanced) use of XSLT - ie, an XML Schema is, itself, an XML document. Therefore, it is a good practice to write an XSLT to generate schema-specific XSLT from the schema itself. That way, if minor changes are made to the XML Schema, he can re-run the 1st XSLT (without having to make any changes to it, if it has been crafted in a 'generic' way) to re-generate the 2nd XSLT - re-generating the 2nd XSLT in this manner simplifies the task of keeping the XSLT and schema in sync with one another.
Re: How to create XSLT for my XML doc?
"Create an XSLT against this schema" IS ambiguous; does it mean:
1. Run the XSLT against the schema itself to create another schema?
2. Run the XSLT against the schema to gain information about it? eg, list all possible attributes.
3. Run the XSLT against xml files based on the schema.
4. Run the XSLT file on another input file to create an xml file based on the schema.
5. Run XSLT on other forms of text, csv, fixed width, etc. to create an xml file based on the schema.
At first glance I would have assumed 3), but the asker turned out to be asking for 4) or 5).
True, for 3 or 4, you could use tools such as Altova's Mapforce (assuming you had both input and output schemas), but I find tools such as these to be generally a waste of time for all but the most-beginner users whom are dependent on a graphical interface. If you can figure out the how things map to each other, why would you need such a tool?
To date, I've found the Stylus Studio Team one of the most reliable commercial teams when it comes to XSLT help, although as of late they have been stingy with their advice if you don't use Stylus Studio. :P Their advice of getting either a schema editor and/or xslt editor is solid; you can't really fault them for trying to push their own product.
Re: How to create XSLT for my XML doc?
Sometimes we need to display the data that are present in a xml file in a tabular format. Following code explan how to display a tabular format of the XML file by applying XSL stylesheet.
XML-FILE
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="showtableformat.xsl"?>
<StudentInfo>
<Students>
<FirstName>Monali</FirstName>
<LastName> Nayak </LastName>
</Students>
<Students>
<FirstName>Sarita</FirstName>
<LastName> Dash </LastName>
</Students>
<Students>
<FirstName>Asrita</FirstName>
<LastName> Pandit </LastName>
</Students>
</StudentInfo>
http://www.mindfiresolutions.com/How...ng-XSL-472.php