Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Grouping by index ... Or something >Thread Next - Re: Grouping by index ... Or something Re: Grouping by index ... Or somethingTo: NULL Date: 12/17/2007 7:22:00 AM On 13 Dec, 14:42, "Anthony Jones" <A...@yadayadayada.com> wrote:
> <richard.hallg...@gmail.com> 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
Hi Anothony!
First, thanks for helping out!
As you guessed my XML is a bit more complicated. I've added the
complete one below to better explain where i wanna go.
<Messages>
<Message1>
<Value>1-1</Value>
</Message1>
<Message1>
<Value>1-2</Value>
</Message1>
<Message2>
<Value>2-1</Value>
</Message2>
<Message2>
<Value>2-2</Value>
</Message2>
<Message3>
<Value>3-1</Value>
</Message3>
</Messages>
Now, there is a relationship between the first Message1 (Value 1-1)
and the first Message2 (Value 2-1). There's also a relationship
between the second Message1 (Value 1-2) and the second Message2 (Value
2-2). Now what I like to do is to make this easier to map at the best
possible performance. I'd like to have a transformation that add group
tags so I get to
<Messages>
<Group>
<Message1>
<Value>1-1</Value>
</Message1>
<Message2>
<Value>2-1</Value>
</Message2>
</Group>
<Group>
<Message1>
<Value>1-2</Value>
</Message1>
<Message2>
<Value>2-2</Value>
</Message2>
</Group>
<Message3>
<Value>3-1</Value>
</Message3>
</Messages>
I can definitely solve this using the solution you show me but would
this be a better idea solving this using somekind og grouping
(Muenchian maybe? I've never actually used that before)? Would that be
the most performing method of solving this you think?
Look forward see your suggestions!
Thanks in advance
Richard
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
