Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL question

Status
Not open for further replies.

ramaanr

Programmer
May 5, 2002
1
US
Hello,
I am using XSL to convert a XML file from one format to another XML file with a different format.
Can I do something like this?
This is my sample original XML file:
<?xml version=&quot;1.0&quot; ?>
<FILE>
<ACCESSION>
<ACCESSION_ID>pacc1</ACCESSION_ID>
<INSTANCE>
<METHOD>m1</METHOD>
<CLASS>c1</CLASS>
<SOURCE>s1</SOURCE>
<NUM_CHAR>1</NUM_CHAR>
<VARIATION>
<VALUE>av1</VALUE>
<COUNT>1</COUNT>
<FREQ>3.1</FREQ>
<POP>pid1</POP>
<POP>pid2</POP>
</VARIATION>
<VARIATION>
<VALUE>av2</VALUE>
<COUNT>1</COUNT>
<FREQ>3.3</FREQ>
<POP>pd1</POP>
</VARIATION>
</INSTANCE>
</ACCESSION>
</FILE>

Can I get an output like:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
- <ROWSET>
- <ROW>
<ACCESSION_ID>pacc1</ACCESSION_ID>
<METHOD>m1</METHOD>
<CLASS>c1</CLASS>
<SOURCE>s1</SOURCE>
<NUM_CHAR>40</NUM_CHAR>
<POLY_INSTANCE_NAME>piname</POLY_INSTANCE_NAME>
- <VALUE>
<VALUE1>av1</VALUE1>
<VALUE2>av2</VALUE2>
</VALUE>
- <COUNT>
<COUNT1>1</COUNT1>
<COUNT2>1</COUNT2>
</COUNT>
- <FREQ>
<FREQ1>3.1</FREQ1>
<FREQ2>3.3</FREQ2>
</FREQ>
- <POP>
<POP1>pop1</POP1>
<POP2>pop2</POP2>
</ROW>
</ROWSET>
Can anyone suggest me how I will be able to get such an output?

The output format which I am able to get is:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
- <ROWSET>
- <ROW>
<ACCESSION_ID>pacc1</ACCESSION_ID>
<METHOD>m1</METHOD>
<CLASS>c1</CLASS>
<SOURCE>s1</SOURCE>
<NUM_CHAR />
<POLY_INSTANCE_NAME />
- <VALUE>
<VALUE>av1</VALUE>
<VALUE>av2</VALUE>
</VALUE>
- <COUNT>
<COUNT>1</COUNT>
<COUNT>1</COUNT>
</COUNT>
- <FREQ>
<FREQ>3.1</FREQ>
<FREQ>3.3</FREQ>
</FREQ>
<POP />
</ROW>

by using the following XSL file:
<!-- chrx-to-variation.xsl -->
<ROWSET xmlns:xsl=&quot; xsl:version=&quot;1.0&quot;>
<xsl:for-each select=&quot; //ACCESSION/INSTANCE&quot;>
<ROW>
<ACCESSION_ID><xsl:value-of select=&quot;../ACCESSION_ID&quot;/></ACCESSION_ID>
<METHOD><xsl:value-of select=&quot;METHOD&quot;/></METHOD>
<CLASS><xsl:value-of select=&quot;CLASS&quot;/></CLASS>
<SOURCE><xsl:value-of select=&quot;SOURCE&quot;/></SOURCE>
<NUM_CHAR><xsl:value-of select=&quot;NUM_CHAR&quot;/></NUM_CHAR>
<POLY_INSTANCE_NAME><xsl:value-of select=&quot;POLY_INSTANCE_NAME&quot;/></POLY_INSTANCE_NAME>
<VALUE><xsl:copy-of select=&quot;VARIATION/VALUE&quot;/></VALUE>
<COUNT><xsl:copy-of select=&quot;VARIATION/COUNT&quot;/></COUNT>
<FREQ><xsl:copy-of select=&quot;VARIATION/FREQ&quot;/></FREQ>
<POP><xsl:copy-of select=&quot;VARIATION/POP&quot;/></POP>
</ROW>
</xsl:for-each>
</ROWSET>


Thanks a lot for your help.

Rama.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top