Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Grouping by index ... Or something

From: "Anthony Jones" <Ant@------------.--->
To: NULL
Date: 12/13/2007 1:43:00 PM

<richard.hallgren@g...> wrote in message
news:5962152b-d307-419b-bf8f-134a746974a2@t......
> Hi,
>
> I have a weird xml fromat that looks something like this (this is just
> a snippet of course):
> ...
> <Node1>
>  <Id>1</Id>
> </Node1>
> <Node1>
>  <Id>2</Id>
> </Node1>
> <Node2>
>  <Name>The first one</Name>
> </Node2>
> <Node2>
>  <Name>The second one</Name>
> </Node2>
> ...
>
> The thing is that the first node1 has a correlation to the first node2
> (in the document I'm mapping to i want to have {Id=1, Name=The first
> one} and {Id=2, Name=The second one}). Performace is key here. How can
> I solve this the easiest way? Or any way ...
>

The problem with over simplifying the example XML is that artificial
solutions appear to work, for example this will generate the sort of output
you need however I doubt that it works for the real world XML.

     <xsl:for-each select="Node2">
      <tr>
       <td><xsl:value-of select="position()" /></td>
       <td><xsl:value-of select="." /></td>
      </tr>
     </xsl:for-each>


What I think you've left us to guess is that there are as many Node1 nodes
as there are Node2 nodes and that there is a one to one relationship between
their ordinal postions.

Here is a something more likely to be what you are after:-

 <xsl:template match="/root">
  <xsl:variable name="node1s" select="Node1" />
  <xsl:variable name="node2s" select="Node2" />
  <html>
   <body>
    <table>
     <xsl:for-each select="$node1s">
      <xsl:variable name="position" select="position()" />
      <tr>
       <td><xsl:value-of select="." /></td>
       <td><xsl:value-of select="$node2s[$position]" /></td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>



-- 
Anthony Jones - MVP ASP/ASP.NET




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