473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

looping output

i have an xml file with links to websites but my output only prints the
1st website from each tag - any ideas why?

i have an an xml file that looks sort of like this:

<?xml version="1.0" encoding="utf-8"?>
<site>
<category type='A'>
<link url="abc.com">abc</link>
</category>

<category type='B'>
<link url="abc1.com">abc1</link>
<link url="abc2.com">abc2</link>
<link url="abc3.com">abc3</link>
</category>
</site>

and my xsl looks like this

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<xsl:for-each select="site//category">

<span>
<xsl:attribute name="class">footer</xsl:attribute>
<xsl:value-of select="@type" />
</span>

<a>
<xsl:attribute name="href"><xsl:value-of select="link"
/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="link" />
</a>

</xsl:for-each>
<p></p>
</xsl:template>
</xsl:stylesheet>

Nov 26 '06 #1
4 2056
i have an xml file with links to websites but my output only prints the
1st website from each tag - any ideas why?
Your XSLT says "for each category, do X", where
X is "emit a link". If you want to do more than one
thing for each category, you'll have to explicitly
say that. You could simply introduce another
for-each loop, like so:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<xsl:for-each select="site//category">

<span>
<xsl:attribute name="class">footer</xsl:attribute>
<xsl:value-of select="@type" />
</span>

<xsl:for-each select="link">
<a>
<xsl:attribute name="href"><xsl:value-of select="."
/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="." />
</a>
</xsl:for-each>

</xsl:for-each>
<p></p>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Ron Burk
www.xmlator.com

Nov 26 '06 #2
I tried that it doesnt produce anything - I tried another for loop
earlier but it didnt work.
xmla...@gmail.com wrote:
i have an xml file with links to websites but my output only prints the
1st website from each tag - any ideas why?

Your XSLT says "for each category, do X", where
X is "emit a link". If you want to do more than one
thing for each category, you'll have to explicitly
say that. You could simply introduce another
for-each loop, like so:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<xsl:for-each select="site//category">

<span>
<xsl:attribute name="class">footer</xsl:attribute>
<xsl:value-of select="@type" />
</span>

<xsl:for-each select="link">
<a>
<xsl:attribute name="href"><xsl:value-of select="."
/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="." />
</a>
</xsl:for-each>

</xsl:for-each>
<p></p>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Ron Burk
www.xmlator.com
Nov 26 '06 #3
I tried that it doesnt produce anything - I tried another for loop
earlier but it didnt work.
Well, given your data (foo.xml) and my corrected stylesheet
(foo.xslt), I type this:

xsltproc foo.xslt foo.xml >foo.out

and then foo.out contains this:

<?xml version="1.0"?>
<span class="footer">A</span><a href="abc" target="_blank">abc</a><span
class="footer">B</span><a href="abc1" target="_blank">abc1</a><a
href="abc2" target="_blank">abc2</a><a href="abc3"
target="_blank">abc3</a><p/>

Did you cut and paste the stylesheet exactly as posted?
If so, what XSLT processor are you using?

Ron Burk
www.xmlator.com

Nov 26 '06 #4
my bad i typed it wrong - your solution does in fact work - thank your
very much
xm*****@gmail.com wrote:
I tried that it doesnt produce anything - I tried another for loop
earlier but it didnt work.

Well, given your data (foo.xml) and my corrected stylesheet
(foo.xslt), I type this:

xsltproc foo.xslt foo.xml >foo.out

and then foo.out contains this:

<?xml version="1.0"?>
<span class="footer">A</span><a href="abc" target="_blank">abc</a><span
class="footer">B</span><a href="abc1" target="_blank">abc1</a><a
href="abc2" target="_blank">abc2</a><a href="abc3"
target="_blank">abc3</a><p/>

Did you cut and paste the stylesheet exactly as posted?
If so, what XSLT processor are you using?

Ron Burk
www.xmlator.com
Nov 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lauren Quantrell | last post by:
I have a table with three columns. One of the columns contains text output data nvarchar(500), one of them contains a filename nvarchar(50), one of the columns is a bit to record if it has been...
2
by: Ruthless | last post by:
Hello. I've got a simple XML: <?xml version="1.0" encoding="iso-8859-2"?> <?xml-stylesheet type="text/xsl" href="4.xsl"?> <struct> <node level="1" no="1">
11
by: Lyle Fairfield | last post by:
The stored procedure script below is an example of how looping, case statements and output parameters can be used in MS-SQL stored procedures to accomplish things for which we may have had to use...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
4
by: Sjoerd | last post by:
Summary: Use foreach(..) instead of while(list(..)=each(..)). --==-- Foreach is a language construct, meant for looping through arrays. There are two syntaxes; the second is a minor but useful...
1
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. ...
7
by: jwatson | last post by:
hey guys need help or some guidances please. Basically its a complicated looping and relational question. Write a program to calculate te percentage score of the mark of the students.The program...
22
Dököll
by: Dököll | last post by:
Hiya, Partners! I have been into it for 12 hours straight this week-end, my son is very unhappy. Looks like I am getting pretty close but need your help, Again. I will post my first...
9
by: brochu121 | last post by:
What I am trying to do is compare two files to each other. If the 2nd file contains the same line the first file contains, I want to print it. I wrote up the following code: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.