Need help with xslt ! Please Help Urgent
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 9
- Joined: Thu Dec 11, 2008 10:15 pm
Need help with xslt ! Please Help Urgent
Hello,
I am new xslt , I have XML , I am trying to create a xslt on these xml.
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="AG FINAL" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="Diameter" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="Flatness" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="RBed" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
I want the output xml in below format.
<Net>
<SName>DOC</SName><Code>666</Code>
<SName>ENG</SName><Code>777</Code>
<SName>TEA</SName><Code>888</Code>
<SName>CLE</SName><Code>999</Code>
</Net>
I am only getting 1 row , that is first rows.
<xsl:element name="Name">
<xsl:value-of select="//@SName"/>
<xsl:element name="Code"">
<xsl:value-of select="//@Code"/>
</xsl:element>
</xsl:element>
output I am getting which is incorrect
<Name>AGR<Code>137</Code>
</Name>
Please help
Thanks
I am new xslt , I have XML , I am trying to create a xslt on these xml.
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="AG FINAL" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="Diameter" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="Flatness" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="RBed" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
I want the output xml in below format.
<Net>
<SName>DOC</SName><Code>666</Code>
<SName>ENG</SName><Code>777</Code>
<SName>TEA</SName><Code>888</Code>
<SName>CLE</SName><Code>999</Code>
</Net>
I am only getting 1 row , that is first rows.
<xsl:element name="Name">
<xsl:value-of select="//@SName"/>
<xsl:element name="Code"">
<xsl:value-of select="//@Code"/>
</xsl:element>
</xsl:element>
output I am getting which is incorrect
<Name>AGR<Code>137</Code>
</Name>
Please help
Thanks
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Need help with xslt ! Please Help Urgent
Hi,
Regards,
George
Code: Select all
<?xml version = "1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Net">
<Net><xsl:apply-templates/></Net>
</xsl:template>
<xsl:template match="Property">
<SName><xsl:value-of select="@SName"/></SName>
<Code><xsl:value-of select="@Code"/></Code>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
-
- Posts: 9
- Joined: Thu Dec 11, 2008 10:15 pm
Re: Need help with xslt ! Please Help Urgent
Hi,
Thanks for answering my question I tried that , But I am getting below result,
Means I am getting All SNames in <SNAME> and Codes in <code>.
see below the output.
<ShortName>DOCENGTEACLE</ShortName>
<Code>666777888999</Code>
But I want something like this
<SName>DOC</SName>
<Code>666</Code>
<SName>ENG</SName>
<Code>777</Code>
<SName>TEA</SName>
<Code>888</Code>
<SName>CLE</SName>
<Code>999</Code>
or
<DOCTOR>
<SName>DOC</SName>
<Code>666</Code>
</DOCTOR>
<ENGINEER>
<SName>ENG</SName>
<Code>777</Code>
</ENGINEER>
<TEACHER>
<SName>TEA</SName>
<Code>888</Code>
</TEACHER>
<CLERK>
<SName>CLE</SName>
<Code>999</Code>
</CLERK>
I applied the below xslt in my original xslt.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<xsl:element name="SName">
<xsl:apply-templates select="//@SName"/>
</xsl:element>
<xsl:element name="Code">
<xsl:apply-templates select="//@Code">
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="YYY DOC" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="XXX ENG" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="ZZZ TEA" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="TTT CLE" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
Thanks for your reply once again !
Thanks for answering my question I tried that , But I am getting below result,
Means I am getting All SNames in <SNAME> and Codes in <code>.
see below the output.
<ShortName>DOCENGTEACLE</ShortName>
<Code>666777888999</Code>
But I want something like this
<SName>DOC</SName>
<Code>666</Code>
<SName>ENG</SName>
<Code>777</Code>
<SName>TEA</SName>
<Code>888</Code>
<SName>CLE</SName>
<Code>999</Code>
or
<DOCTOR>
<SName>DOC</SName>
<Code>666</Code>
</DOCTOR>
<ENGINEER>
<SName>ENG</SName>
<Code>777</Code>
</ENGINEER>
<TEACHER>
<SName>TEA</SName>
<Code>888</Code>
</TEACHER>
<CLERK>
<SName>CLE</SName>
<Code>999</Code>
</CLERK>
I applied the below xslt in my original xslt.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<xsl:element name="SName">
<xsl:apply-templates select="//@SName"/>
</xsl:element>
<xsl:element name="Code">
<xsl:apply-templates select="//@Code">
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="YYY DOC" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="XXX ENG" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="ZZZ TEA" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="TTT CLE" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
Thanks for your reply once again !
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Need help with xslt ! Please Help Urgent
If you apply the stylesheet I posted on your XML data then you will get
In your stylesheet you match on the document root node and output exactly two elements, so what you see as result is exactly what one would expect from that stylesheet.
Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Net>
<SName>DOC</SName><Code>666</Code>
<SName>ENG</SName><Code>777</Code>
<SName>TEA</SName><Code>888</Code>
<SName>CLE</SName><Code>999</Code>
</Net>
Regards,
George
George Cristian Bina
-
- Posts: 9
- Joined: Thu Dec 11, 2008 10:15 pm
Re: Need help with xslt ! Please Help Urgent
Yes, I agree with your answer,
But the xml I gave is part of my original xml, It is not the whole xml.
So template is already open with "/" in the xslt, If I open the template again Its not allowing me, Its says the element should be given at top level.
Thanks
techza
But the xml I gave is part of my original xml, It is not the whole xml.
So template is already open with "/" in the xslt, If I open the template again Its not allowing me, Its says the element should be given at top level.
Thanks
techza
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Need help with xslt ! Please Help Urgent
That's right, you cannot nest one template inside another. See my example, it has two templates, they are top level elements inside stylesheet.
Best Regards,
George
Best Regards,
George
George Cristian Bina
-
- Posts: 9
- Joined: Thu Dec 11, 2008 10:15 pm
Re: Need help with xslt ! Please Help Urgent
Hi,
Thanks for replying to messages.
Maybe you will understand the exactly what I am trying to do,
Below is the xml file look like
I have also put the comments between <<<<< >>>>>>>>
<xml version="1.0" encoding="UTF-8">
<Parent>
<certificate>
<label>NumberAB: </label>
<inumber>ZZZZ</number>
<label> Number: </label>
<desc> IN</desc>
<Contain>
<<<<<<<<<<< Other then Code and SName all the data is coming from this elements
---------------------------
</contain>
</Certificate>
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="YYY DOC" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="XXX ENG" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="ZZZ TEA" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="TTT CLE" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
</Parent>
</xml>
MY XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<xsl:element name="File">
<xsl:element name="FileInfo">
<xsl:element name="Email">tom@yahoo.com</xsl:element>
</xsl:element>
<xsl:element name="Sites"">
<xsl:element name="Description">
<xsl:element name="Number">44444</xsl:element>
<xsl:element name="Name">TNZ</xsl:element>
<xsl:element name="Code">55555</xsl:element>
<xsl:element name="QualityCertificates">
<xsl:for-each select="//GMAT"
<xsl:element name="Number">
<xsl:value-of select="//proddesc" />
</xsl:element>
--------------------
----------------------
----------------------
<<<<<<<<<<< I have lot of other elements created here ,
which is calling the other data >>>>>>>>>>>>>>>
----------------
-----------------
-----------------
-------------
<SName>
<Code>
<<<<<<<<<<<<<<I want the sName and the Code here,
which is coming from the other template> <QxML> tags >>>>>>>>>>>>>>>>.
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
To Open a new template I have to open after this template right ?
If I open the template before or after this template how do I call the template for applying the template
I know you can help, becuase you undersood what I am trying to get here.
thanks
Syed
Thanks for replying to messages.
Maybe you will understand the exactly what I am trying to do,
Below is the xml file look like
I have also put the comments between <<<<< >>>>>>>>
<xml version="1.0" encoding="UTF-8">
<Parent>
<certificate>
<label>NumberAB: </label>
<inumber>ZZZZ</number>
<label> Number: </label>
<desc> IN</desc>
<Contain>
<<<<<<<<<<< Other then Code and SName all the data is coming from this elements
---------------------------
</contain>
</Certificate>
<Qxml>
<Qxml>
<Net>
<Property Name="DOCTOR" SName="DOC" LongDesc="YYY DOC" Code="666" STC="1"/>
<Property Name="ENGINEER" SName="ENG" LongDesc="XXX ENG" Code="777" STC="2"/>
<Property Name="TEACHER" SName="TEA" LongDesc="ZZZ TEA" Code="888" STC="3"/>
<Property Name="CLERK" SName="CLE" LongDesc="TTT CLE" Code="999" STC="4"/>
</Net>
</Qxml>
</Qxml>
</Parent>
</xml>
MY XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<xsl:element name="File">
<xsl:element name="FileInfo">
<xsl:element name="Email">tom@yahoo.com</xsl:element>
</xsl:element>
<xsl:element name="Sites"">
<xsl:element name="Description">
<xsl:element name="Number">44444</xsl:element>
<xsl:element name="Name">TNZ</xsl:element>
<xsl:element name="Code">55555</xsl:element>
<xsl:element name="QualityCertificates">
<xsl:for-each select="//GMAT"
<xsl:element name="Number">
<xsl:value-of select="//proddesc" />
</xsl:element>
--------------------
----------------------
----------------------
<<<<<<<<<<< I have lot of other elements created here ,
which is calling the other data >>>>>>>>>>>>>>>
----------------
-----------------
-----------------
-------------
<SName>
<Code>
<<<<<<<<<<<<<<I want the sName and the Code here,
which is coming from the other template> <QxML> tags >>>>>>>>>>>>>>>>.
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
To Open a new template I have to open after this template right ?
If I open the template before or after this template how do I call the template for applying the template
I know you can help, becuase you undersood what I am trying to get here.
thanks
Syed
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service