473,847 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl:foreach

mickey0
142 New Member
Hello,
I just this question:
Expand|Select|Wrap|Line Numbers
  1.     <xsl:for-each select="//tag1">
  2.       <xsl:value-of select="text()" />
  3.     </xsl:for-each>
  4.  
my output is:
hello;world;
I need:
Hello;
World;

my xslt header is:
Expand|Select|Wrap|Line Numbers
  1.        <xsl:output method="text"                 
  2.                    encoding="iso-8859-1"           
  3.                    indent="yes"                
  4.  
My output file is a text file.....
How can I do this, please?

Best regards,
Jul 9 '08 #1
16 3961
roces
7 New Member
You can concatenate text() with line feed entity "&#xD;".

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.    <xsl:for-each select="//tag1">
  3.      <xsl:value-of select="concat(text(), '&#xD;')"/>
  4.    </xsl:for-each>
  5. </xsl:template>
Jul 10 '08 #2
mickey0
142 New Member
hi thanks,
what do you think if I add it inside a text tag? is this better or not?
Expand|Select|Wrap|Line Numbers
  1. <xsl:text>>&#xD;</xsl:text> 
sometimes I need to do this too:
Expand|Select|Wrap|Line Numbers
  1.  <xsl:text>>printf("hello");&#xD;</xsl:text>  
or indent the braces:
Expand|Select|Wrap|Line Numbers
  1.  <xsl:text>>         } &#xD;</xsl:text>  
What do you suggest for these aims?

Thanks,
Jul 10 '08 #3
roces
7 New Member
I think it's absolutely normal, but variant with concatenation is more readable than your. Compare:

Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="concat( 'your_text', text(), '>         }  ', some_tag_value, 'your_text2')"/>
  2.  
and

Expand|Select|Wrap|Line Numbers
  1. <xsl:text>your_text</xsl:text><xsl:value-of select="text()/><xsl:text>>         }  </xsl:text><xsl:value-of select="some_attrib_value"/><xsl:text>your_text2</xsl:text>
  2.  
Jul 10 '08 #4
mickey0
142 New Member
thanks,
seem ok, but the function concat(), where I can find explanation about other function too?
Why doens't these below work?
Expand|Select|Wrap|Line Numbers
  1.              indent="yes"           
  2.               xalan:indent-amount="2"/>
  3.  
Jul 10 '08 #5
roces
7 New Member
It's xalan specific instruction. I think U need to read some docs about it. )
Jul 11 '08 #6
mickey0
142 New Member
Thanks; a further question if possible....
The text in the xml contains this string inside a tag: "hello\nwor ld" (and I mean not the new line but the '\' follow by 'n'
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="concat( 'PRINT(', text(), ');'  /> 
  2. //produce in the output file:
  3. PRINT(hello\nworld);
  4.  
while I need in the output text file:
Expand|Select|Wrap|Line Numbers
  1. PRINT(hello);
  2. PRINT(world);
  3.  
How can I do this, please?
Jul 11 '08 #7
roces
7 New Member
<xsl:value-of select="concat( 'PRINT(',
replace(text(), '\n', &#xD;),
');' />
Jul 14 '08 #8
mickey0
142 New Member
<xsl:value-of select="concat( 'PRINT(',
replace(text(), '\n', &#xD;),
');' />
hello,

it seems there's a problem to put the "(" ")" of replace inside a concat......Do you know it? Is there any trick, please?

thanks,
Jul 14 '08 #9
roces
7 New Member
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="concat( 'PRINT(', 
  2.                                                             replace(text(), '\n',  ), 
  3.                                                           ');' "/>
I forgot double quote at the end of "select" attribute. And you just need to pay attention to the code and read more docs ))
Jul 15 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2861
by: Marcel | last post by:
Hello all, I am working on a generic (php) script to produce (X)HTML Forms through XML and XSL based on field-definitions stored in a database. The basic way i did HTML-forms in PHP was like this: http://212.204.203.71/test/simpleform/simpleform.php source: http://212.204.203.71/test/syntax/simpleform.php
1
1512
by: Spam sucks | last post by:
hello, i create a logging xml file with dom that could have an unknown count of results now it is 0 to 7 but it could be i have 14 or 50 results how can you read this out with xsl, with php you would put it in an array or something but now i want to do it with xsl. in php it woul be like: foreach ($array as $key=>$value) {
3
11550
by: Tjerk Wolterink | last post by:
Hello, I want to create m elements in this form: <element index="n"/> Where n = 1 2 .. m Can is do this with an xsl:for loop?? And if so how
3
2464
by: Tjerk Wolterink | last post by:
I posted my problem earlier, but i simplified the examples, and i know what the cause of the problem is, but i dont know the solution, my xml file: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="datastyle.xsl"?> <data xmlns="http://tjerk.com"> <item>a1</item> <item>b2</item>
2
1629
by: Dirk McCormick | last post by:
I need to transform something that looks like this <!-- %%%%%%%%%%%%%%%%%%%%%%% --> <MyStructure> <Packages> <Package> <PkgBenefitCode>1</PkgBenefitCode> <PkgBenefitCode>2</PkgBenefitCode> <PkgBenefitCode>3</PkgBenefitCode>
3
1620
by: rene | last post by:
Hello everybody, i have these 2 xml files ------1.xml------ <?xml version="1.0" encoding="UTF-8"?> <root> <element>1</element> <element>2</element> </root>
0
886
by: George Durzi | last post by:
Bear with me on this one because the explanation might be a bit lengthy. I have a stored procedure which is returning three tables (using three SELECTs). Table 0 is a list of all bills for a job (relates to Table 1 by GB_JOB_ID) Table 1 is a list of all jobs (relates to Table 2 by ACCOUNT_MANAGER_ID) Table 2 is a list of all sales people Not all jobs have bills associated with them. (I think this is where my problem is, but read on)....
5
1411
by: nutsmuggler | last post by:
Hi. I am using xml to store my annotations. here is my document (a part of it): <?xml version="1.0" encoding="UTF-8"?> <text title="Finnegan's wake"> <book number="1"> <chapter number="5"> <note p="107"> script: <q>proteiform graph, polyhedron of scripture, etc</q>
2
1227
by: Andrus | last post by:
xml data <?xml version="1.0" ?> <statement> <accounts> <account number="22"> <currency symbol="USD"> <transactions> <transaction> <id>1</id>
0
9889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9732
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10709
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10343
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9486
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7058
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4535
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4125
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.