 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 30th, 2003, 04:25 PM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello xsl friends
I'm very familiar with xml and xsl -- however, I do have a question. :D
IN my xml map - I have several elements like:
<plan1>
<plan2>
<plan3>
<plan4>
<plan5>
<plan6>
through
<plan106>
I'm doing a lot of substring and contains and length and concat in my XSL.
I want to know.. In xsl, can you do something similiar to "for loop" for the <plan[i]> that will assign 1,2,3,4,5 to plan.
Now i'm creating individual XPATH for each plan1, plan2, etc... So, I have 106 set of instructions in the xsl when I should have one.
Thanks for your help. It is greatly appreciated.
Michael Hall
|
|

October 31st, 2003, 04:51 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Is there any particular reason you named the nodes like that? Does, say, plan1 have a different structure than plan2? If you had used <plan id="1">...<plan id="2"> etc then you wouldn't have this problem. Please elaborate on the structure and what you're trying to accomplish.
|
|

October 31st, 2003, 02:22 PM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi PGtips,
Thanks for replying.
Here's my XML MAP:
<NOTE>
<ATTRIB Name="PLNOTES1" Field="BNDS1" dt="string" />
<ATTRIB Name="PLNOTES2" Field="BNDS2" dt="string" />
<ATTRIB Name="PLNOTES3" Field="BNDS3" dt="string" />
<ATTRIB Name="PLNOTES4" Field="BNDS4" dt="string" />
<ATTRIB Name="PLNOTES5" Field="BNDS5" dt="string" />
<ATTRIB Name="PLNOTES6" Field="BNDS6" dt="string" />
<ATTRIB Name="PLNOTES7" Field="BNDS7" dt="string" />
<ATTRIB Name="PLNOTES8" Field="BNDS8" dt="string" />
<ATTRIB Name="PLNOTES9" Field="BNDS9" dt="string" />
<ATTRIB Name="PLNOTES10" Field="BNDS10" dt="string" />
<ATTRIB Name="PLNOTES11" Field="BNDS11" dt="string" />
<ATTRIB Name="PLNOTES12" Field="BNDS12" dt="string" />
<ATTRIB Name="PLNOTES13" Field="BNDS13" dt="string" />
<ATTRIB Name="PLNOTES14" Field="BNDS14" dt="string" />
<ATTRIB Name="PLNOTES15" Field="BNDS15" dt="string" />
<ATTRIB Name="PLNOTES16" Field="BNDS16" dt="string" />
<ATTRIB Name="PLNOTES17" Field="BNDS17" dt="string" />
<ATTRIB Name="PLNOTES18" Field="BNDS18" dt="string" />
<ATTRIB Name="PLNOTES19" Field="BNDS19" dt="string" />
<ATTRIB Name="PLNOTES20" Field="BNDS20" dt="string" />
THROUGH
<ATTRIB Name="PLNOTES106" Field="BNDS106" dt="string" />
</NOTE>
__________________________________________________ ______________
My XSL:
<xsl:choose>
<xsl:when test="contains(NOTE/@PLNOTES1, '|')">
<tr>
<TD Class="SmData" width="50%" align="left">
<xsl:value-of select="substring-before(NOTE/@PLNOTES1, '|')" />
</TD>
<TD Class="SmData" width="50%" align="left">
<xsl:value-of select="substring-after(NOTE/@PLNOTES1, '|')" />
</TD>
</tr>
</xsl:when>
<xsl:when test="contains(NOTE/@PLNOTES1, '*****') or substring(NOTE/@PLNOTES1, 1, 4) = '----'"> <tr>
<TD colspan="2" Class="SmData" width="689" align="center">
<xsl:value-of select="NOTE/@PLNOTES1" />
</TD>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<TD colspan="2" Class="SmData" width="100%" align="left">
<xsl:value-of select="NOTE/@PLNOTES1" />
</TD>
</tr>
</xsl:otherwise>
</xsl:choose>
I do thses instructions inside XSL 106 times - really. It goes from NOTE/@PLNOTES1, NOTE/@PLNOTES2, NOTE/@PLNOTES3, etc...
There must be a way to do something similar to a FOR LOOP? Correct?
Thanks for your help,
Mike
|
|

November 3rd, 2003, 04:54 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Umm, maybe I'm missing something, but can't you just do:
<xsl:for-each select="NOTE/@*">
<xsl:choose>
<xsl:when test="contains(., '|')">
...etc
</xsl:for-each>
|
|

November 3rd, 2003, 11:33 AM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi pgtips,
Thanks, it works fantastic! I had a (For Each) like your example, but I coded <xsl:for-each select="NOTE/@PLNOTES*"> and it didn't work.
Again - Thanks for your time -- I appreciate it greatly.
Thanks,
Mike
|
|
 |