xml and xsl Nested for-each and if statements

G

Guest

I am having trouble figuring out how to make this work:

I have data being returned in a template (xml file) from a web interface.

In a simplified view one section of data might look like this.

<RESULTS>
<NAMES>
<RESULT>
<ADDRESS>some address here</ADDRESS>
<ALIASES>
<ALIAS>John Smith</ALIAS>
<ALIAS>J Smith</ALIAS>
<ALIAS>John Q Smith</ALIAS>
</ALIASES>
</RESULT>
<RESULT>
<ADDRESS>some other address here</ADDRESS>
<ALIASES>
<ALIAS>Betty Smith</ALIAS>
<ALIAS>B Smith</ALIAS>
<ALIAS>Betty R Smith</ALIAS>
</ALIASES>
</RESULT>
</NAMES>
<RESULTS>

What I am trying to do is assign each Address and Alias to a variable, which
I am able to do with the xsl template:

Using the following logic:

<xsl:for-each select="RESULTS/NAMES/RESULT">
<xsl:if test="position() = 1">

I can assign the Address to a respective variable, ie ResultAddress1 and
ResultAddress2.

When I try to do a nested for-each loop,

<xsl:for-each select="RESULTS/NAMES/RESULT">
<xsl:if test="position() = 1">

<xsl:for-each select="ALIASES">
<xsl:if test="position() = 1">
assign first Alias to a variable here
<xsl:if test="position() = 2">
assign second Alias to a variable here
<xsl:if test="position() = 3">
assign third Alias to a variable here

Unfortunately all I can get is the first alias, even if the name has 3
aliases, the test=position() = 1 is true for both loops.

---

How can perform a nested for-each loop using xsl and the sample data above.

In this model I would have 8 Variables defined to save data:

For results #1
ResultAddress1
Alias1_1
Alias1_2
Alias1_3

For results #2
ResultsAddress2
Alias2_1
Alias2_2
Alias2_3

Thanks for the help
J
 
A

Ada Pan [MSFT]

Hello Customer,

From the post log, it seems that you need assistance on XML/XSL. For <
XML/XSL > side questions, we have dedicated newsgroups:

microsoft.public.xml
microsoft.public.xsl

Please submit your question to those newsgroups, as there are more
qualified pools of respondents who can give you suggestions. Meanwhile,
other partners who visit the newsgroups regularly can either share their
knowledge or learn from your interaction with us.

Thank you for your understanding.

Regards,

Ada Pan

Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
====================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top