Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with xlst

From: "Stefan Misch" <stefan.misch@----------.---.-->
To: NULL
Date: 3/2/2006 11:44:00 AM
Hi,

first I added a root-element to your simplified sample, to get a well-formed 
XML:

<root>
 <tablename>MyTableName</tablename>
 <field>
  <name>MyFieldName1</name>
  <value>MyFieldValue1</value>
 </field>
 <field>
  <name>MyFieldName2</name>
  <value>MyFieldValue2</value>
 </field>
</root>

Then I used the following XSL to do the transformation:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml"/>
 <xsl:template match="/root">
  <root>
   <xsl:apply-templates/>
  </root>
 </xsl:template>
 <xsl:template match="tablename">
  <tablename><xsl:value-of select="."/></tablename>
 </xsl:template>
 <xsl:template match="field">
  <xsl:variable name="vFieldName" select="name"/>
  <xsl:element name="{$vFieldName}">
   <xsl:value-of select="value"/>
  </xsl:element>
 </xsl:template>
</xsl:stylesheet>

The result is:

<root>
 <tablename>MyTableName</tablename>
 <MyFieldName1>MyFieldValue1</MyFieldName1>
 <MyFieldName2>MyFieldValue2</MyFieldName2>
</root>

HTH,
Stefan


<fdlane61@g...> schrieb im Newsbeitrag 
news:1141249607.148049.155630@e......
>I receive an xml file from an external system and would like to
> transform the output.
>
> The file looks as follows:
> .....
> <tablename>MyTableName</tablename>
> <field>
> <name>MyFieldName1</name>
> <value>MyFieldValue1</value>
> </field>
> <field>
> <name>MyFieldName2</name>
> <value>MyFieldValue2</value>
> </field>
> .....
>
> I would like to transform it to the following:
>
> <tablename>MyTableName</tablename>
> <MyFieldName1>MyFieldValue1</MyFieldName1>
> <MyFieldName2>MyFieldValue2</MyFieldName2>
>
>
> Can this be done?
>
> TIA
>
> DeWayne
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent