Copy XML Nodes with an Iteration

I've got a question about copying some xml, with xslt.

I have xml that sometimes contains Parent nodes with an iteration. They look like this.

<opdracht iteration="1">
         <a> 1 </a>
         <b> 1 </b>
</opdracht>
<opdracht iteration="2">
         <a> 1 </a>
         <b> 1 </b>
</opdracht>
<opdracht iteration="3">
         <a> 1 </a>
         <b> 1 </b>
</opdracht>

If i choose 3 items, the xml will build 3 iterated nodes. But if I choose 5 of 6 items, it generates 5 or 6 different xml iterations.

I need to make some XSLT that allows me to copy these parent and child Iterated nodes, for as long as they are iterated. And output them under the same original name. So :

<opdracht iteration="1"> Becomes <opdracht>
And
<opdracht iteration="2"> becomes also <opdracht>

And so forth....

How do I do this?

Answers


I don't fully understand the question, but I "think" you are saying you want to copy the XML, but remove the @iteration attribute from the opdracht elements.

If that is the case, you can do it with a simple extension to the XSLT identity transform

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

   <xsl:template match="opdracht/@iteration" />

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

When applied to the following XML

<root>
<opdracht iteration="1"> 
         <a> 1 </a> 
         <b> 1 </b> 
</opdracht> 
<opdracht iteration="2"> 
         <a> 1 </a> 
         <b> 1 </b> 
</opdracht> 
<opdracht iteration="3"> 
         <a> 1 </a> 
         <b> 1 </b> 
</opdracht> 
</root>

The following is output:

<root>
  <opdracht>
    <a> 1 </a>
    <b> 1 </b>
  </opdracht>
  <opdracht>
    <a> 1 </a>
    <b> 1 </b>
  </opdracht>
  <opdracht>
    <a> 1 </a>
    <b> 1 </b>
  </opdracht>
</root>

Need Your Help

Display datetime into MM/dd/yyyy HH:mm format c#

c# asp.net datetime

In database datetime is being stored in MM-dd-yyyy HH:mm:ss fromat.

Fluent NHibernate (with automapping) not saving join table values in many-to-many

c# nhibernate fluent-nhibernate automapping

I am not exactly an NHibernate expert, so this may be a lack of understanding in that department. I have two simple entities with a many-to-many relationship

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.