|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need XSLT Elements help
Hi,
I am trying to create a xslt to pull the data from the input xml file, I pasted it below the message , I tried everything But I am getting below result, Means I am getting All SNames in <SNAME> and Codes in <code>. see below the output. <SName>DOCENGTEACLE</SName> <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:""><!-- I removed the url --> <xsl utput 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> My Input XML file <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 Techza |
|
#2
|
|||
|
|||
|
I've seen this problem before. Is this a schoolwork question?
You seem to want one element per property. Change it up to this then: Code:
<xsl:template match="/"> <xsl:apply-templates select="//Property"/> </xsl:template> <xsl:template match="Property"> <xsl:element .... Where do you get your element name? From the Property's Name attribute. However, this is set inside the name attribute, so you must use braces {} to execute the xpath Code:
<xsl:element name="{@Name}">
Then it appears you want your SName and Code elements. Declare these directly for cleaner code. Code:
<xsl:element name="{@Name}">
<SName><xsl:value-of select="@SName"/></SName>
<Code><xsl:value-of select="@Code"/></Code>
|
|
#3
|
|||
|
|||
|
Template not working
Hi,
Thanks for your reply, My actual looks like this below, there are lot of data in <Opel> elements, which I am getting using the xslt <xml version="1.0" encoding="UTF-8"> <parent Type= "T" display="N " > <view></view> <Opel> -------- -------- </Opel> <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> In your reply , you want me to open the template, But I think we cannot open the template inside the template. when i put the code you provided in to my xslt I am getting an error message that template elements should be given at top level <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="( <xsl utput method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" /><xsl:template match="/"> <xsl:element name="File"> <xsl:element name="File"> <xsl:for-each select="//Opel"> <xsl:element name="File"> <xsl:value-of select="//@RBI TRANS"/> </xsl:element> ---------------- -------------- I want the Sname & Code here. Please help If you can , Thanks Techza |
|
#4
|
|||
|
|||
|
Are you referring to apply-templates inside the template?
eg see http://www.w3schools.com/xsl/xsl_apply_templates.asp I want the Sname & Code here. -> becomes -> <xsl:apply-templates select="//Property"/> |
|
#5
|
|||
|
|||
|
xslt template and elements
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="(: See forum rules)" version="1.0"> <xsl utput 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> I know you can help, because you understood what I am trying to get here. thanks |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Need XSLT Elements help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|