[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Iteration in XSL

Subject: RE: Iteration in XSL
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Thu, 28 Dec 2000 17:25:58 -0000
xsl array iteration
Daniel,
Beginners rule number 1
*NEVER* use xsl:for-each
What is wrong with doing it like this

<?xml version='1.0' encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
  <html>
	<body>
		<xsl:apply-templates />
	</body>
  </html>
</xsl:template>
<xsl:template match="section">
	<xsl:apply-templates />
</xsl:template>
<xsl:template match="sectiontitle">
	<b><xsl:value-of select="." /></b><br />
</xsl:template>
<xsl:template match="subsectiontitle">
	<i><xsl:value-of select="." /></i><br />
</xsl:template>
<xsl:template match="sectiontext">
	<xsl:value-of select="." /><br />
</xsl:template>
</xsl:stylesheet>

Or variation on that theme.

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


>-----Original Message-----
>From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Daniel
>Celdran
>Sent: 28 December 2000 16:28
>To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
>Subject:  Iteration in XSL
>
>
>Hello,
>
>I have the next DTD:
>
>File: section.dtd
><?xml version="1.0" encoding="UTF-8"?>
><!ELEMENT sectiontitle (#PCDATA)>
><!ELEMENT subsectiontitle (#PCDATA)>
><!ELEMENT sectiontext (#PCDATA)>
><!ELEMENT section (sectiontitle+, subsectiontitle*, sectiontext+)>
>
>As you can see, the "section" element can contain more than one
>"sectiontext" (which is a normal situation).
>I try to do a XSL file to transform the XML files created from this DTD and
>I have problems if the XML contains more than one "sectiontext",
>for example
>the next XML file:
>
>File: example1.xml
><?xml version="1.0" encoding="UTF-8"?>
><?xml-stylesheet type="text/xsl" href="section.xsl"?>
><!DOCTYPE section SYSTEM "C:\work\section.dtd">
><section>
>	<sectiontitle>First section</sectiontitle>
>	<subsectiontitle>section's subtitle</subsectiontitle>
>	<sectiontext>First text for the first section</sectiontext>
>	<sectiontext>Second text for the first section</sectiontext>
></section>
>
>It haves two "sectiontext", for accessing to this information from the XSL
>file, I made the next XSL file
>
>File: section.xsl
><?xml version='1.0' encoding="UTF-8"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
><xsl:template match="/">
>  <html>
>	<body>
>		<xsl:for-each select="section">
>				<b><xsl:value-of
>select="sectiontitle"/></b><br></br>
>				<i><xsl:value-of
>select="subsectiontitle"/></i><br></br>
>				<xsl:value-of
>select="sectiontext[0]"/><br></br>
>				<xsl:value-of
>select="sectiontext[1]"/><br></br>
>				<br></br>
>		</xsl:for-each>
>	</body>
>  </html>
></xsl:template>
></xsl:stylesheet>
>
>As you can see, I access to the differents "sectiontext" elements
>as if they
>were an array, but I don't know how can I get the number of
>elements of this
>array for make it as an iteration process.
>I want to know if there is another way for accessing to all the
>"sectiontext" elements without using the array position.
>I have try to do it using the '<xsl:for-each select="sectiontext">' or
>'<xsl:for-each select="section/sectiontext">' but it doesn't run.
>
>How can I solve this??
>
>Thanks in advance and excuse me for my English mistakes.
>
>Daniel Celdran
>danielceldran@xxxxxxxxxxxxxxxx
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.