Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2004

Tip: Looking for answers? Try searching our database.

XSL - to insert a node

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Beniamin Tecar - 10 Sep 2004 10:15 GMT
Hi,
I have an xml :

<DataRecords>
   <Point Alias='A' Value='1' Status='0' />
   <Point Alias='B' Value='2' Status='0' />
</DataRecords>
I have needed by an XSL to insert a node between <DataRecords> and <Point>

Example :

<DataRecords>
   <Record>
       <Point Alias='A' Value='1' Status='0' />
   </Record>
   <Record>
       <Point Alias='B' Value='2' Status='0' />
   </Record>
</DataRecords>

Can anyone help me?

Thanks

Beni
Martin Honnen - 10 Sep 2004 12:39 GMT
> I have an xml :
>
[quoted text clipped - 14 lines]
>     </Record>
> </DataRecords>

Simply use the identity transformation and add one template for <Point>
elements that wraps them into a <Record> element:

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

<xsl:output method="xml" encoding="UTF-8" />

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
  </xsl:copy>
</xsl:template>

<xsl:template match="Point">
  <Record>
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </Record>
</xsl:template>

</xsl:stylesheet>

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

Randal Chapman - 10 Sep 2004 17:53 GMT
> <DataRecords>
>     <Point Alias='A' Value='1' Status='0' />
>     <Point Alias='B' Value='2' Status='0' />
> </DataRecords>

> <DataRecords>
>     <Record>
[quoted text clipped - 4 lines]
>     </Record>
> </DataRecords>

<xsl:for-each select="DataRecords/Point">
 <xsl:text disable-output-escaping="yes">&lt;Record&gt;</xsl:text>
 <Point>
   <xsl:attribute name="Alias"><xsl:value-of select="@Alias" /></xsl:attribute>
   <xsl:attribute name="Value"><xsl:value-of select="@Value" /></xsl:attribute>
   <xsl:attribute name="Status"><xsl:value-of select="@Status" /></xsl:attribute>
 <xsl:text disable-output-escaping="yes">&lt;/Record&gt;</xsl:text>
</xsl:for-each>

_Randal

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.