This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Iteration in XSL
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Iteration in XSL
- From: Daniel Celdran <danielceldran at CONTENTARENA dot com>
- Date: Thu, 28 Dec 2000 17:28:18 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
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@contentarena.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list