XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
zakir techSubject: need xslt elements help
Author: zakir tech
Date: 24 Jun 2009 01:03 PM
Hi,

I am trying to create a xslt to get the data from my input xml file,
I don't know what i am doing wrong here.

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: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>



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

Posttop
(Deleted User) Subject: need xslt elements help
Author: (Deleted User)
Date: 26 Jun 2009 06:30 AM
Hi,
you are not iterating over the elements. Try something like this

<xsl:template match="/">
<xsl:for-each select="//Property">

<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:for-each>
</xsl:template>

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.