Hello,

I have XML , I am trying to create a xslt on these xml.

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


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>DOC<Code>666</Code>
</Name>

Please help

Thanks

Here is one way of doing it

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes" />

<xsl:template match="Property">
   <xsl:element name="SName">
   <xsl:value-of select="@SName" />
   </xsl:element>
   <xsl:element name="Code">
   <xsl:value-of select="@Code" />
   </xsl:element>
   <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="Net">
   <xsl:element name="Net">
   <xsl:text>&#10;</xsl:text>
   <xsl:apply-templates select="Property" />
   </xsl:element>
</xsl:template>

</xsl:stylesheet>

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.

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

<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


Here is one way of doing it

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes" />

<xsl:template match="Property">
   <xsl:element name="SName">
   <xsl:value-of select="@SName" />
   </xsl:element>
   <xsl:element name="Code">
   <xsl:value-of select="@Code" />
   </xsl:element>
   <xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="Net">
   <xsl:element name="Net">
   <xsl:text>
</xsl:text>
   <xsl:apply-templates select="Property" />
   </xsl:element>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" media-type="xml"/>
	<xsl:template match="/">
		<Net>
			<xsl:apply-templates select="//Property"/>
		</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>

Helmut Hagemann

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

send the xml and xsl
to me ICQ 567877710
Helmut Hagemann

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.