Avatar of gayathri grandhe
gayathri grandhe
 asked on

could you please suggest me that in order to repeat elements by using for-each loop instead of giving path in xslt

in order to repeat elements by using for-each loop instead of giving path in xslt
* XSLTXML* XSL

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
mccarl

Can you provide some examples of what you are providing as input to the transformation and what you expect as output?
gayathri grandhe

ASKER
Normally is there any other way instead of giving path to the for-each loop in xslt.
For Example:In C,C++ there is a for loop in order to repeat the elements such as
 for(i=0;i<3;i++)
{
printf("test");
}
in the above example the printf statement executes 3 times.
like the same way i need to repeat the steps in the xslt by using for-each loop.
could you please provide the solution to that as soon as possible.
Gertone (Geert Bormans)

You usually get the answers you deserve based on the clarity of the question.
Please, if you ever ask a question again, make sure it can be understood

If you would be using XSLT2 this is fairly easy
        <xsl:for-each select="for $i in 1 to 3 return $i">
            <!-- do something here -->
            <xsl:value-of select="."/>
        </xsl:for-each>

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gayathri grandhe

ASKER
Hi Greet,


I used the logic which you have given. but the following error is generating for me.

Error:Expected token 'eof' found '$'. for -->$<--i in 1 to 2 return $i
 

And i used this piece of code.but the error is generating.

<xsl:for-each select="for $i in 1 to 2 return $i">
 
 <xsl:element name="Policies">
<xsl:attribute name="Update">successfull</xsl:attribute>
<xsl:element name="AssuredRefernceihlp">correct</xsl:element>
<xsl:element name="PoliciesOption">Quote65</xsl:element>
</xsl:element>
 
</xsl:for-each>

could you please suggest me in that.
Gertone (Geert Bormans)

Please note that I clearly wrote
If you would be using XSLT2 this is fairly easy
Are you using XSLT2?
Gertone (Geert Bormans)

It is clear that the select in the for each does not accept the '$' so it does not accept an XPath 2.0 expression
so you are obviously not using XSLT
tell us which XSLT processor you are using maybe we can switch that to XSLT2
if not use the recursive solution that works in any case
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gayathri grandhe

ASKER
<xsl:call-template name="iterate">
            <xsl:with-param name="left" select="3"/>
        </xsl:call-template>

I used this solution it is working fine now.

But I have another question  is that is there any possible way "that tags want to be repeated and the values should be different" by using for-each loop in xslt.
I need code for this. could you please assist me.

For example :<insurance>akil</insurance>
<insurance>hari</insurance>
like this tags need to be repeated. But the values must be different.
that it should be done with for-each loop in xslt.
Gertone (Geert Bormans)

Yes, that is possible
but you need to explain the logic

It sounds as if you should use some sort of lookup XML
<ins>
<in>akil</in>
<in>hari</in>
</ins>
and use XPath on those and forget about the for-each iterator
Your wording of your issues is very vague and underspecified, so I can't comment on the entire project
but I fear you are thinking too proocedural
gayathri grandhe

ASKER
instead of xpath is there any other possible way
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Gertone (Geert Bormans)

Maybe XPath is the best way,
but you are not answering my questions
but you need to explain the logic

You launch some vague bizarre requirements,
you are not explaining what you need, you are just saying that it has to be without XPath

Unless you explain very clear and in detail what exactly you need,
I will consider this question answered
please accept #a42052333
as the answer and we are done with this
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gayathri grandhe

ASKER
Actually i need to do xslt transformation from one xml(1st xml)to another xml(2nd xml) by using xslt.
But the two xml's format are completely different.
but in the second xml the tags (elements)are repeating with different values that tags are not there in 1st xml. so i thought that we cannot use xpath for that.
so, for that purpose iam asking for the logic of the iterators
Gertone (Geert Bormans)

well, try my latest suggestion
(I don't think you need to do it that way, but let's just try that)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gayathri grandhe

ASKER
how to retrieve namespace of one xml to another xml by using xslt through xpath
gayathri grandhe

ASKER
I mean how to extract the namespace of xml by using xslt through xpath. is it is possible?
Gertone (Geert Bormans)

yes, but that is a completely different question, you should not mix questions, ask a new one and close this one please
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Gertone (Geert Bormans)

It is obvious that the solutions provided were used and should be accepted. They are definitely complete.
The original poster of the question tried to add a completely different questions inside this thread and then ran off... kind of sad