Subject: RE: [xsl] Iteration in XSL From: "Chris Bayes" <Chris@xxxxxxxxxxx> Date: Thu, 28 Dec 2000 17:25:58 -0000 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Iteration in XSL, Daniel Celdran | Thread | [xsl] Conditional text using attrib, Beth Fischi |
Re: [xsl] Conditional text using at, Steve Muench | Date | RE: [xsl] Conditional text using at, Chris Bayes |
Month |