XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2009, 01:08 PM
techza techza is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 techza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 41 sec
Reputation Power: 0
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 -->
<xslutput 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

Reply With Quote
  #2  
Old June 24th, 2009, 02:33 PM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 576 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 3 h 58 m 24 sec
Reputation Power: 55
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>

Reply With Quote
  #3  
Old June 24th, 2009, 09:00 PM
techza techza is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 techza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 41 sec
Reputation Power: 0
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="(
<xslutput 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

Reply With Quote
  #4  
Old June 25th, 2009, 03:43 PM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 576 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 3 h 58 m 24 sec
Reputation Power: 55
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"/>

Reply With Quote
  #5  
Old June 26th, 2009, 03:27 PM
techza techza is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 techza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 41 sec
Reputation Power: 0
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">
<xslutput 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Need XSLT Elements help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT